Deleting Error Records

by Oct 11, 2010

In a previous tip, you learned that "Continue" can skip code in a loop. Another scenario for using "Continue" is error handling. Inside your trap, "Continue" deletes the error record and prevents it from bubbling up, so that additional upstream error handlers would not handle the error any more:

Trap { "Whew, an error: $_"continue } 1/$null

Without "Continue", your handler would trigger, but the exception would continue to bubble up, so PowerShell’s own handler would also see it and toss in a red PS error message as well.

Twitter This Tip!
ReTweet this Tip!