# Why does this error not catch?

**URL:** <https://forums.powershell.org/t/why-does-this-error-not-catch/4730>\
**Category:** PowerShell Help\
**Created:** [August 20, 2015, 4:58am UTC](https://forums.powershell.org/t/why-does-this-error-not-catch/4730 "2015-08-20T04:58:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![windows-liveuser49](https://avatars.discourse-cdn.com/v4/letter/w/c68b51/32.png) [@windows-liveuser49](https://forums.powershell.org/u/windows-liveuser49)\
**Post date:** [August 20, 2015, 4:58am UTC](https://forums.powershell.org/t/why-does-this-error-not-catch/4730/1 "2015-08-20T04:58:33Z")

</div>

This first line in the try block won’t get caught and gives me the associated error, but if I switch out those lines it will get caught by my catch. Why is that?

Try  
{  
new-alias start “thisshouldntwork”  
#get-procajksdfjdksa  
}  
Catch { Write-Output “ERROR” }

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [August 20, 2015, 5:04am UTC](https://forums.powershell.org/t/why-does-this-error-not-catch/4730/2 "2015-08-20T05:04:55Z")

</div>

Because most cmdlets don’t generate a trappable, terminating exception by default. See “The Big Book of PowerShell Error Handling” (free, Resources menu here to find the ebooks). Essentially, you need to probably add the -ErrorAction parameter.

Some cmdlets also _never_ generate a trappable, terminating exception. That’s in the cmdlet design, and there’s not much you can do about it.

---

<div class="post-metadata">

**Author:** ![windows-liveuser49](https://avatars.discourse-cdn.com/v4/letter/w/c68b51/32.png) [@windows-liveuser49](https://forums.powershell.org/u/windows-liveuser49)\
**Post date:** [August 20, 2015, 5:27am UTC](https://forums.powershell.org/t/why-does-this-error-not-catch/4730/3 "2015-08-20T05:27:00Z")

</div>

Ah, good to know, thanks, I’ll check out that book.

---

<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:44pm UTC](https://forums.powershell.org/t/why-does-this-error-not-catch/4730/4 "2024-05-16T20:44:52Z")

</div>


