There are two types of Error. Terminating and non-terminating.
A terminating error is an error that will halt a function or operation. If you make a syntax error or run out of memory, that is a terminating error. Terminating errors can be caught and handled.
Non-terminating errors allow Powershell to continue and usually come from cmdlets or other managed situations. Under normal circumstances they cannot be caught by Try-Catch-Finally.
So how to catch a Non-Terminating error?
Basically, we need to tell PowerShell to treat it as terminating. To do this you use the ErrorAction parameter. By specifying -ErrorAction Stop on the end of a cmdlet you ensure that any errors it throws are treated as terminating and can be caught.
Once you have ensured that the error you are trying to catch is going to be treated as terminating, you can build a Try Catch block around the command (or commands) that might cause the error. The first stage is to surround the section of your script that may throw the error with a Try block. Immediately after the Try block you must place a Catch block to deal with the error. The Catch block is only accessed if a terminating error occurs, otherwise it is ignored.
In my case, I have a workflow to deploy a storage system.
But sometimes, it can fail half way after creating the aggregates.
So the next time I run, I want the skip the part of creating aggregates since its already created.
One choice is remove the steps and create new references to the aggregates (cumbersome).
So I was wondering if there is a any recommended way to skip steps in a workflow when required and I tried ErrorAction which did not work in this case (because trying to create a aggregate that already exists is a terminating error).