Error handling

Hi,
I’ve tried to find some info about error handling in the unreal engine but didn’t have found anything. So how the error handling/processing is done in unreal?

It looks like the exceptions aren’t allowed in the default build of the projects/engine (One can set some build options to allow exceptions but then how the exceptions are handled? How about unhandled exceptions?). I’ve found some asset macros in the docs. How does one raise an error without continuing the program flow? That is something like throwing exception? Is it done using the assert macro? What about release builds?

I think some documentation could be added about error handling (if it does already exist I’ll glad to be aware of it).

Thanks

3 Likes

Am assuming you are coming from C# background.
In C++ you can use the keywords like (try, catch).

I know many C++ programmers don`t use them, and i remember when reading some starter books back in the day.
That it was “bad practice” to use them in many cases, C++ code should not expect any errors you code to prevent them.

Ether way use regular expresions and UE_LOG macros and so on.
Thats my 2 cents on the subject anyway.

Thanks for reply,
I am a C++ developer, actually.

I don’t agree with your argument about not using exceptions in C++. Exceptions are heavily used in STL and boost. But that’s not a point .

I would like to hear from the unreal developers what’s the code guidelines regarding the error handling.

Anyway, how do you use regex for the error handling (Because I can’t see the point using regex in error handling)? AFAIK UE_LOG() doesn’t stop the execution of the current program flow, it only logs the error. But if I’m in the situations if some preconditions aren’t met, I don’t want to continue execution because UB could happens, which is never good.

4 Likes

May be u need to use FPlatformMisc::SetCrashHandler, im not sure though.
If you want to catch exceptions and continue, forget about it, exceptons must be used only for crashes, otherwise all functions have “return error code” versions if needed.

There are a few options available to you;

  • check() verify() and ensure() etc. are macros that act like asserts. See Engine\Source\Runtime\Core\Public\Misc\AssertionMacros.h for more details about these.
  • Also, UE_LOG(Fatal, …) will stop execution. Other ‘log levels’ like Log, *Verbose *etc. will not.
5 Likes

Thanks Tom for the reply.

I was thinking that UE_LOG(Fatal, …) could stop the execution, but wasn’t sure. Thanks for the confirmation.

Sorry for reviving this old post, but just to get it clear:
Using the default UE engine build, throwing your own exceptions is possible inside your code?

If is there any standard guide on how to handle errors in your UE project, that would be handy as well.

Thanks :wink:

3 Likes

bump

that would be handy

1 Like

Just randomly got here while googling the property name and since it’s the first result and couple people have asked stuff in comments, here we go:
Module Properties in Unreal Engine | Unreal Engine 5.2 Documentation

bEnableExceptions (Boolean)
Enable exception handling.

So if you want to use exceptions - add a line bEnableExceptions = true in the .build.cs file of the module you want to use them in. Just be careful as if it would get to the engine code you would get a termination. Plus, AFAIK it is problematic to mix code with and without exceptions enabled on linux, so your game may become non-portable without rebuilding the engine. But I don’t remember the exact details on this, so if you want that, just google about the topic before deciding. Plus, blueprints are completely unable to handle them even if you rebuild the entire engine. I’d bet it’s the main reason exceptions are disabled by default.

2 Likes