Last active
December 28, 2015 19:03
-
-
Save trondhindenes/a1d72085d9c727bd8910 to your computer and use it in GitHub Desktop.
ErrorWeirdness
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Inner | |
{ | |
[CmdletBinding()] | |
Param () | |
Try | |
{ | |
throw "Inner exception" | |
} | |
Catch | |
{ | |
Return $null | |
} | |
Return "yep" | |
} | |
Function Outer | |
{ | |
[CmdletBinding()] | |
Param () | |
Try | |
{ | |
$a = Inner -ErrorAction Stop -ErrorVariable "innerErr" | |
} | |
Catch | |
{ | |
} | |
if ($a -eq $null) | |
{ | |
Write-Error "An error occurred" | |
} | |
} | |
Outer -ErrorAction SilentlyContinue -ErrorVariable myvar | |
$myvar |
That is truly bizarre behavior.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running in PSv4, the errorobject ($myvar) only contains one error record. Running in PSv5, the inner exception from the child function is also surfaced.