LuaBridge3 icon indicating copy to clipboard operation
LuaBridge3 copied to clipboard

Create custom luabridge exceptions

Open kunitoki opened this issue 1 year ago • 2 comments

To be able to catch individual exceptions when raised by luabridge, we should create specific derived exception types.

kunitoki avatar Apr 17 '23 18:04 kunitoki

This seems like a reasonable step to me. I would suggest that it derive from std::runtime_error.

As a side note, I went looking to see how it would differ from LuaException and discovered this:

inline void enableExceptions(lua_State* L) noexcept
{
#if LUABRIDGE_HAS_EXCEPTIONS
    LuaException::enableExceptions(L);
#else
    unused(L);

    LUABRIDGE_ASSERT(false); // Never call this function when exceptions are not enabled.
#endif
}

Would it not be safer to do it this way? (Thinking about the principal of failing early, this would fail at compile time rather than run time.):

#if LUABRIDGE_HAS_EXCEPTIONS
inline void enableExceptions(lua_State* L) noexcept
{
    LuaException::enableExceptions(L);
}
#endif

rpatters1 avatar Apr 19 '23 11:04 rpatters1

Yes makes sense

kunitoki avatar Apr 19 '23 21:04 kunitoki