Why can't I catch a luabind::error exception when my lua code throws an error?

吃可爱长大的小学妹 提交于 2019-11-28 04:19:43

问题


When you call a LUA function from c++ and there is a runtime error LuaBind throws a luabind::error exception that you can catch and then read the stack to see what the error was. My debugger definitely catches this exception but when I let the debugger continue, instead of the exception being caught in my code the program immediately terminates.

The exception is thrown in "call_member.hpp" in the LuaBind include files from the destructor ~proxy_member_void_caller().

The problem occurs with simple test code. I am using Xcode 5 with LuaBind 0.9.1.


回答1:


It turns out that it is bad practice to throw exceptions in destructors. With C++11 destructors are implicitly noexcept(true), so if an exception occurs the program terminates. LuaBind uses exceptions in destructors, so on my modern compiler the program terminated. Editing the method signature to:

~proxy_member_void_caller() noexcept(false) {}

allows you to catch exceptions from LuaBind in c++11.



来源:https://stackoverflow.com/questions/23574323/why-cant-i-catch-a-luabinderror-exception-when-my-lua-code-throws-an-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!