Error handling

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).


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 here.

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.

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.

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: