Cannot use 'try' with exceptions disabled

Hello everyone,

I’m trying to build the project for android but get an error:

C:\Users\Vadim\Documents\Unreal Projects\ClearAIProject\Source\ClearAIProject\Private\AI\BotAIController.cpp(1129,1) :  error: cannot use 'try' with exceptions disabled
MainFrameActions: Packaging (Android (All)): UnrealBuildTool: try

How to enable ?

UE4 does not use exceptions (“try” is part of exception feature) so it not configured to enable them, here something that may help you:

You should find android configs in intermediate directory, if UBT gonna overwrite anything you will need to dig in his configuration or even code

Unreal discourages the use of c++'s exception system. There are several reasons behind this design decision. Use of exceptions can immensely complicate the code, especially in intricate systems like UE. It can also lead to memory leaks. However, these issues are arguably due to the poor language design itself, and may not arise in other languages so often, and even among c++ developers the use of exceptions is considered an open discussion.
Rather than recovering from failures later, the Epic team proposes checking things in advance instead.
You can use assertion macros to report unexpected behaviors (both unrecoverable and recoverable). You can also use “checked” functions (like CastChecked) which automatically crash with diagnostic messages if something is not correct. Most of the time, it’s about passing null pointers or unsupported configurations - only major errors are causing this to happen.
This approach seems brutal at first, but it does not allow for hiding errors under any circumstances.
If, however, you absolutely can’t get away without using exceptions, look through the first link and try what is suggested there, it might or might not work on newer engine versions.

“poor language design” is pretty unrelated to C++ though

1 Like