Search

Advanced Functions + Exceptions by jdaltry

Active

2
0
Sign in
to vote
Type: Bug
ID: 779361
Opened: 2/16/2013 5:54:32 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug

In PowerShell v3, when the $ErrorActionPreference is 'Stop' and a .NET method throws an exception in an advanced function, the resulting error is non-terminating (script execution continues).
Details (expand)
How often does this happen?
Always Happens

Have you seen this problem before in this product?

No, this is new to the most recent version
Reproduction Steps

function Foo {
[CmdletBinding()]
Param()
$ErrorActionPreference = 'Stop'
[datetime]::Parse('xyz')
Write-Host 'Foo'
}

Foo
Write-Host 'After Foo'
Expected Results

In the example above, the exception raised from the Parse method should generate a terminating error and cause script execution to stop. Instead, function execution stops but script execution continues.

Advanced functions should work just like regular functions.
File Attachments
0 attachments
Sign in to post a comment.
Sign in to post a workaround.