godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.75k stars 580 forks source link

Throw exception in GDNative cause game stop without message #600

Open nongvantinh opened 3 years ago

nongvantinh commented 3 years ago

With a simple throw std::exception the game stop without printing the message from the exception.

Calinou commented 3 years ago

Godot is not compiled with exceptions enabled, so I think this is expected behavior. Use the error macros at your disposal instead, such as ERR_FAIL_*(). You can return values of the Error enum to use as error codes.

nongvantinh commented 3 years ago

So I can't make the program stop. Print an error message is all I can do.

ghost commented 3 years ago

Just use get_tree()->quit(1); after ERR_ macro

Calinou commented 3 years ago

There's also the CRASH_NOW() macro you can use.