Last active
March 7, 2018 19:18
-
-
Save Jaykul/7d46df2bd74a45e4ce7379a4575f9f99 to your computer and use it in GitHub Desktop.
Minimal effort at error logging
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 Verb-Noun { | |
[CmdletBinding()] | |
param() | |
Push-Location -Stack Verb-Noun | |
# BOILER PLATE ERROR HANDLING | |
trap { # Standard practice in every script | |
$ex = $_ | |
do { | |
$Stack = if($ex.ScriptStackTrace) { $ex.ScriptStackTrace } else { $ex.StackTrace } | |
$PSCmdlet.WriteInformation(@( | |
$ex.GetType().Fullname | |
"Stack Trace:" | |
($Stack | Out-String -width 100) -split "`n" -replace "^\s*"," " | |
) -join "`n", ("PSHOST", "Exception")) | |
} while($ex = if($ex.Exception) { $ex.Exception } else { $ex.InnerException }) | |
Pop-Location -Stack Verb-Noun | |
throw | |
} $ErrorActionPreference = "Stop" | |
# YOUR CODE GOES HERE | |
} |
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
[CmdletBinding()] | |
param() | |
# BOILER PLATE ERROR HANDLING | |
trap { # Standard practice in every script | |
$ex = $_ | |
do { | |
$Stack = if($ex.ScriptStackTrace) { $ex.ScriptStackTrace } else { $ex.StackTrace } | |
$PSCmdlet.WriteInformation(@( | |
$ex.GetType().Fullname | |
"Stack Trace:" | |
($Stack | Out-String -width 100) -split "`n" -replace "^\s*"," " | |
) -join "`n", ("PSHOST", "Exception")) | |
} while($ex = if($ex.Exception) { $ex.Exception } else { $ex.InnerException }) | |
throw | |
} $ErrorActionPreference = "Stop" | |
# YOUR CODE GOES HERE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment