# How do I escape an inescapable error?

**URL:** <https://forums.powershell.org/t/how-do-i-escape-an-inescapable-error/14987>\
**Category:** PowerShell Help\
**Created:** [September 23, 2020, 12:58am UTC](https://forums.powershell.org/t/how-do-i-escape-an-inescapable-error/14987 "2020-09-23T00:58:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![panzerbjrn](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/panzerbjrn/32/36_2.png) [@panzerbjrn](https://forums.powershell.org/u/panzerbjrn)\
**Post date:** [September 23, 2020, 12:58am UTC](https://forums.powershell.org/t/how-do-i-escape-an-inescapable-error/14987/1 "2020-09-23T00:58:14Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [September 23, 2020, 4:56am UTC](https://forums.powershell.org/t/how-do-i-escape-an-inescapable-error/14987/2 "2020-09-23T04:56:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![grokkit](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grokkit/32/970_2.png) [@grokkit](https://forums.powershell.org/u/grokkit)\
**Post date:** [September 23, 2020, 5:05am UTC](https://forums.powershell.org/t/how-do-i-escape-an-inescapable-error/14987/3 "2020-09-23T05:05:12Z")

</div>

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`?

---

<div class="post-metadata">

**Author:** ![panzerbjrn](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/panzerbjrn/32/36_2.png) [@panzerbjrn](https://forums.powershell.org/u/panzerbjrn)\
**Post date:** [September 23, 2020, 5:18am UTC](https://forums.powershell.org/t/how-do-i-escape-an-inescapable-error/14987/4 "2020-09-23T05:18:46Z")

</div>

> [@](#):
>
> 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.

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?

---

<div class="post-metadata">

**Author:** ![panzerbjrn](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/panzerbjrn/32/36_2.png) [@panzerbjrn](https://forums.powershell.org/u/panzerbjrn)\
**Post date:** [September 23, 2020, 5:23am UTC](https://forums.powershell.org/t/how-do-i-escape-an-inescapable-error/14987/5 "2020-09-23T05:23:15Z")

</div>

[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(?)…

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [September 23, 2020, 5:36am UTC](https://forums.powershell.org/t/how-do-i-escape-an-inescapable-error/14987/6 "2020-09-23T05:36:57Z")

</div>

> [@](#):
>
> And why would anyone not have their $erroractionpreeeference set to stop?

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

```
PS C:\Users\rasim> $ErrorActionPreference
Continue
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:28pm UTC](https://forums.powershell.org/t/how-do-i-escape-an-inescapable-error/14987/7 "2024-05-16T20:28:49Z")

</div>

Closed on May 16, 2024, 8:28pm UTC


