How do I escape an inescapable error?

Some cmdlets give error that aren’t cought by Try/Catch blocks and/or don’t respect -ErrorAction Stop/Continue.
Two examples that spring to mind are Get-AzStorageContainer, Add-PnPListItem and Get-SwisData from the Az.Storage, SharePointPnPPowerShellOnline and SwisPowerShell modules respectively.

So my question is, how do I catch errors from cmdlets that doesn’t respect Try/Catch blocks, and thus terminate my scripts unintentionally?

Take a look at the Free Resources > Ebooks for The Big Book of PowerShell Error Handling. Using a try\catch with ErrorAction Stop catches terminating errors. I’ve had issues when you are in a remote session that you have to globally turn erroraction to stop, the command erroraction did not work.

Do they return any error message, or any kind of output, or does your script just crash out?
Can you reproduce the failure conditions intentionally and reliably?
What do you see if you execute them with Set-PSDebug -Trace 2?

Thanks Rob, but if you had read my post, you would have seen that I am using Try/Catch blocks.
And why would anyone not have their $erroractionpreeeference set to stop?

[quote quote=258323]Do they return any error message, or any kind of output, or does your script just crash out?

Can you reproduce the failure conditions intentionally and reliably?

Yes, Get-AzStorageContainer and Get-SwisData reliably bombs out, and give their own, I assume, internal error messages. Add-PnPListItem sometimes does the same, and sometimes errors and continues, without respecting any error action preference.

I will try the trace, although I doubt it will help me in catching the errors(?)…

Well, the default in Powershell is Continue, not Stop:

PS C:\Users\rasim> $ErrorActionPreference
Continue