# Try/Catch fails to catch exception?

**URL:** <https://forums.unrealengine.com/t/try-catch-fails-to-catch-exception/463146>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [March 31, 2020, 11:06pm UTC](https://forums.unrealengine.com/t/try-catch-fails-to-catch-exception/463146 "2020-03-31T23:06:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vib](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vib/32/88718_2.png) [@vib](https://forums.unrealengine.com/u/vib)\
**Post date:** [March 31, 2020, 11:06pm UTC](https://forums.unrealengine.com/t/try-catch-fails-to-catch-exception/463146/1 "2020-03-31T23:06:27Z")

</div>

UE4 crashes randomly about 1% of the time at one specific line in my code with Unhandled Exception: EXCEPTION\_ACCESS\_VIOLATION. I have no idea what’s causing the crash so I put a Try/Catch at that line figuring at least the game wouldn’t crash if it happens and just fail gracefully instead. But the game is still crashing anyway even with the Try/Catch.

How is that possible? What can I do to stop the crash? How could I possibly debug this to try to figure what’s wrong? How can the error say “Unhandled Exception” when there’s a Try/Catch? Doesn’t the Try/Catch, by definition, means it’s handled? Isn’t that the whole point of why God created the Try/Catch in the first place?

My code at MyCharacter.cpp where the crash happens at line 278:

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/5/9/9597ffb5b3f6a93c238affef0d2ec6dd66c84623.png)

The stack trace:

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/4/d/04d48934a07db8391c56268e5a6918d9434d592b.png)

[Link to Code and full Stack Trace in text format.][3]

[Link to project.][4]

---

<div class="post-metadata">

**Author:** ![Dongsj28](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dongsj28](https://forums.unrealengine.com/u/Dongsj28)\
**Post date:** [December 24, 2020, 8:31pm UTC](https://forums.unrealengine.com/t/try-catch-fails-to-catch-exception/463146/2 "2020-12-24T20:31:17Z")

</div>

I have the same problem.How did you solve it?

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [December 24, 2020, 8:44pm UTC](https://forums.unrealengine.com/t/try-catch-fails-to-catch-exception/463146/3 "2020-12-24T20:44:09Z")

</div>

UE4 code don’t support exceptions (it simply does not use it). Instead function just return false, nullptr or some other state if it fails.

UE4 also practice code assertion, if UE4 detect unexpected condition (it does check) it crash the engine with failed condition in log. It reason why you barely see Access Violation from the engine fault… it will asset fail before that happens.

---

<div class="post-metadata">

**Author:** ![vib](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vib/32/88718_2.png) [@vib](https://forums.unrealengine.com/u/vib)\
**Post date:** [December 24, 2020, 8:53pm UTC](https://forums.unrealengine.com/t/try-catch-fails-to-catch-exception/463146/4 "2020-12-24T20:53:59Z")

</div>

I was never able to track down exactly what was causing that specific problem. But it was probably the garbage collector deleting something that it shouldn’t. Basically you have to put a UPROPERTY() on every class variable that you can, so the GC works properly with them. Once I put UPROPERTY() on everything, those errors stopped happening.

---

<div class="post-metadata">

**Author:** ![Raz1789](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Raz1789](https://forums.unrealengine.com/u/Raz1789)\
**Post date:** [July 7, 2022, 9:24pm UTC](https://forums.unrealengine.com/t/try-catch-fails-to-catch-exception/463146/5 "2022-07-07T21:24:41Z")

</div>

Just to expand on the point @vib mentioned, you don’t need to put on everything, just any type of pointers that you want to hold on to. For non-UObject type pointers, use the std c++ smart pointers. Basic datatypes and structures are not GC’d.

---

<div class="post-metadata">

**Author:** ![phil123456](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@phil123456](https://forums.unrealengine.com/u/phil123456)\
**Post date:** [April 19, 2023, 7:40am UTC](https://forums.unrealengine.com/t/try-catch-fails-to-catch-exception/463146/6 "2023-04-19T07:40:42Z")

</div>

> [@Shadowriver](#):
>
> UE4 code don’t support exceptions

try catch is a language feature

---

<div class="post-metadata">

**Author:** ![letthemicefree](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/letthemicefree/32/989563_2.png) [@letthemicefree](https://forums.unrealengine.com/u/letthemicefree)\
**Post date:** [May 12, 2023, 2:32am UTC](https://forums.unrealengine.com/t/try-catch-fails-to-catch-exception/463146/7 "2023-05-12T02:32:17Z")

</div>

Unfortunately (or fortunately, depending on how you see it 😅 ) in UE you’re not using Vanilla C++. I believe the way to handle error is with the check, verify, ensure families of functions. See : [Asserts in Unreal Engine | Unreal Engine 5.2 Documentation](https://docs.unrealengine.com/5.2/en-US/asserts-in-unreal-engine/)

And actually its preferable from a performance standpoint as well, which is why using try/catch is unsupported in UE territory.
