Created
December 11, 2012 13:41
-
-
Save akimboyko/4258647 to your computer and use it in GitHub Desktop.
PowerShell exception re-throwing sample
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
Write-Host 'throw' | |
try | |
{ | |
try | |
{ | |
throw "exception" | |
} | |
catch | |
{ | |
Write-Host $_ | |
Write-Host $_.GetType() | |
Write-Host $_.Exception | |
Write-Host $_.Exception.StackTrace | |
throw | |
} | |
} | |
catch | |
{ | |
Write-Host $_ | |
Write-Host $_.GetType() | |
Write-Host $_.Exception | |
Write-Host $_.Exception.StackTrace | |
Write-Host $err | |
} | |
Write-Host 'throw (exception)' | |
try | |
{ | |
try | |
{ | |
$exception = New-Object System.Exception ("test") | |
throw $exception | |
} | |
catch | |
{ | |
Write-Host $_ | |
Write-Host $_.GetType() | |
Write-Host $_.Exception | |
Write-Host $_.Exception.StackTrace | |
throw | |
} | |
} | |
catch | |
{ | |
Write-Host $_ | |
Write-Host $_.GetType() | |
Write-Host $_.Exception | |
Write-Host $_.Exception.StackTrace | |
Write-Host $err | |
} | |
Write-Host 'throw $_' | |
try | |
{ | |
try | |
{ | |
$exception = New-Object System.Exception ("test") | |
throw $exception | |
} | |
catch | |
{ | |
Write-Host $_ | |
Write-Host $_.GetType() | |
Write-Host $_.Exception | |
Write-Host $_.Exception.StackTrace | |
throw $_ | |
} | |
} | |
catch | |
{ | |
Write-Host $_ | |
Write-Host $_.GetType() | |
Write-Host $_.Exception | |
Write-Host $_.Exception.StackTrace | |
Write-Host $err | |
} | |
Write-Host 'throw $_.Exception' | |
try | |
{ | |
try | |
{ | |
$exception = New-Object System.Exception ("test") | |
throw $exception | |
} | |
catch | |
{ | |
Write-Host $_ | |
Write-Host $_.GetType() | |
Write-Host $_.Exception | |
Write-Host $_.Exception.StackTrace | |
throw $_.Exception | |
} | |
} | |
catch | |
{ | |
Write-Host $_ | |
Write-Host $_.GetType() | |
Write-Host $_.Exception | |
Write-Host $_.Exception.StackTrace | |
Write-Host $err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment