Find whether PowerShell error is originally Terminating or non-terminating

964 views Asked by At

Lets say I ran a command with ErrorAction Stop and it generated an error. I would like to know whether the error was originally terminating or not? I have the ErrorVariable or $Error object. Does ErrorVariable catches both kind of errors? I am looking for a property in .NET/PowerShell object which could tell me that this Error was terminating. Are exceptions generated for Non-Terminating errors too?

Plus, when I am writing a command on console (not ISE and not running a script, just single command on console), how can I suppress the Error using ErrorAction variable? Basically, there should not be any red output on the screen.

1

There are 1 answers

6
Seth On

about_Try_Catch_Finally and about_Trap have some helpful information.

By default non terminating errors aren't caught by try catch but they will show up in $error. You can use -ErrorVariable to define another error variable (about_CommongParameter. So you could use a custom variable for a check for non terminating errors which might make your code easier readable.

By using SilentlyContinue the output is suppressed but the error is still recorded in the error variable.