本文介绍了当我的lua代码引发错误时,为什么我无法找到一个luabind ::错误异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您从c ++调用LUA函数并且有运行时错误时,LuaBind会抛出一个luabind :: error异常,您可以捕获然后读取堆栈以查看错误。我的调试器肯定会捕获这个异常,但是当我让调试器继续下去,而不是在我的代码中捕获的异常,程序立即终止。



异常被抛出在call_member LuaBind中的.hpp包含来自析构函数〜proxy_member_void_caller()的文件。



简单测试代码出现问题。我正在使用Xcode 5与LuaBind 0.9.1。

解决方案

事实证明,它是。使用C ++ 11析构函数隐式 noexcept(true),所以如果程序终止异常。 LuaBind在析构函数中使用异常,所以我的现代编译器程序终止。编辑方法签名到:

 〜proxy_member_void_caller()noexcept(false){} 

允许您从c ++ 11中的LuaBind捕获异常。


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.

解决方案

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.

这篇关于当我的lua代码引发错误时,为什么我无法找到一个luabind ::错误异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 19:08