lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I know that the standard way to handle errors in library codes is to call C API lua_error. However, instead of calling lua_error, I throw a normal C++ exception in library codes, what will happen?


In addition, I built Lua sources as C++ codes. So the macro LUAI_TRY in luaconf.h was defined as try-catch(…) statement. Therefore, the protected calls(lua_pcall) use try-catch(…) instead of setjmp/longjmp. I write library codes in C++ as well. In my test program, I called lua_pcall with an error handler. Then, when I called lua_error in the library function, the error handler was called and lua_pcall returned LUA_ERRRUN. That’s expected behavior. But when I thrown a C++ exception in the library function, the exception was caught by catch(…) within macro LUAI_TRY and the error handler was not called, lua_pcall returned -1. However, I could use this lua_State for the further calls.


Now, my question is whether it is safe to throw an C++ exception in such context. Does it miss anything about cleanup or state settings? And, does it place the lua_State instance in an inconsistent state?


周惟迪 | Zhou Wei Di |