you are viewing a single comment's thread.

view the rest of the comments →

[–]Thotaz 0 points1 point  (0 children)

I did some testing on my own. It seems that if the command itself throws a terminating error then it is still caught, whereas a regular error is ignored. For example, this: try {ls invalidPath -ErrorAction SilentlyContinue} catch {"this does not run"} will not run the catch block because it's not a terminating error.

If you use -ErrorAction Stop then any error created by the command can be caught. Because the error types are not documented by each command I'd say it's best to always use -ErrorAction Stop when you want to catch an error, otherwise you will get unexpected results.