reactphysics3d icon indicating copy to clipboard operation
reactphysics3d copied to clipboard

Wrap exceptions behind a define

Open Mcela opened this issue 3 years ago • 1 comments

Hello!

I think it might be useful to wrap these few throws behind __cpp_exceptions (or some other explicit USE_EXCEPTIONS define), since most game engines disable them, or remove them completely as there's asserts there anyways:

In file included from ./lib/reactphysics3d/include/reactphysics3d/memory/HeapAllocator.h:34:
./lib/reactphysics3d/include/reactphysics3d/containers/Map.h:386:29: error: cannot use 'throw' with exceptions disabled
                            throw std::runtime_error("The key and value pair already exists in the map");
                            ^
./lib/reactphysics3d/include/reactphysics3d/containers/Map.h:572:17: error: cannot use 'throw' with exceptions disabled
                throw std::runtime_error("No item with given key has been found in the map");
                ^
./lib/reactphysics3d/include/reactphysics3d/containers/Map.h:585:17: error: cannot use 'throw' with exceptions disabled
                throw std::runtime_error("No item with given key has been found in the map");

./lib/reactphysics3d/include/reactphysics3d/utils/DefaultLogger.h:364:25: error: cannot use 'throw' with exceptions disabled
                        throw(std::runtime_error("ReactPhysics3D Logger: Unable to open an output stream to file " + mFilePath));

Also a big thank you for creating the library! It's super useful to have a lightweight physics lib like this, and the code is very clear and readable. Opens a lot of doors.

Mcela avatar Feb 25 '22 12:02 Mcela

Oh sorry. I just saw that I have never answered your question. Very sorry for that.

Anyway, thanks a lot for your feedback.

Yes, that's a good point. My goal is not to use exceptions in the ReactPhysics3D code. Therefore, I will see if I can improve that.

DanielChappuis avatar Aug 04 '22 12:08 DanielChappuis

In the last version of the library (version v0.10.0), I have removed the code throwing exceptions.

DanielChappuis avatar Mar 10 '24 13:03 DanielChappuis