Skip to content

Instantly share code, notes, and snippets.

@csharpforevermore
Created May 30, 2015 18:52
Show Gist options
  • Save csharpforevermore/131df838e3aa9dd97e03 to your computer and use it in GitHub Desktop.
Save csharpforevermore/131df838e3aa9dd97e03 to your computer and use it in GitHub Desktop.
Powershell - get current exception line number and details
$e = $_.Exception
$line = $_.InvocationInfo.ScriptLineNumber
$msg = $e.Message
Write-Host -ForegroundColor Red "caught exception: $e at $line"
Write-Host -ForegroundColor Red "An exception occurred."
Write-Host -ForegroundColor Red '$_ = ' $_
Write-Host -ForegroundColor Red '$_.GetType().FullName = ' $_.GetType().FullName
Write-Host -ForegroundColor Red '$_.Exception = ' $_.Exception
Write-Host -ForegroundColor Red '$_.Exception.GetType().FullName = ' $_.Exception.GetType().FullName
Write-Host -ForegroundColor Red '$_.Exception.Message = ' $_.Exception.Message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment