Skip to content

Instantly share code, notes, and snippets.

@akimboyko
Created December 11, 2012 13:41
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save akimboyko/4258647 to your computer and use it in GitHub Desktop.
Save akimboyko/4258647 to your computer and use it in GitHub Desktop.
PowerShell exception re-throwing sample
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