Skip to content

Instantly share code, notes, and snippets.

@trondhindenes
Last active December 28, 2015 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trondhindenes/a1d72085d9c727bd8910 to your computer and use it in GitHub Desktop.
Save trondhindenes/a1d72085d9c727bd8910 to your computer and use it in GitHub Desktop.
ErrorWeirdness
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
@trondhindenes
Copy link
Author

Running in PSv4, the errorobject ($myvar) only contains one error record. Running in PSv5, the inner exception from the child function is also surfaced.

@alx9r
Copy link

alx9r commented Dec 28, 2015

That is truly bizarre behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment