Created
January 7, 2022 16:41
-
-
Save JohnL4/bb1c1b3e6b5663982c6d4e81fd10ef84 to your computer and use it in GitHub Desktop.
Catch and log an exception (for some value of "log") with a script stack trace for later debugging
This file contains 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
# Wrap your entire script in a try-catch block: | |
try { | |
# Do stuff | |
} | |
catch { | |
Write-Error ("{0}`n{1}" -f $_, $_.ScriptStackTrace) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment