Re: [luabind] catching a luabind::error and getting info from it
Brought to you by:
arvidn,
daniel_wallin
From: Arvid N. <c9...@cs...> - 2004-06-29 22:08:54
|
Kevin Watters wrote: > I'm running into problems getting good error information from > luabind::error exceptions that get thrown when there are errors in Lua > functions I call from C++ code. If you just use e.what() all you get is > "lua runtime error," which isn't quite descriptive enough for my needs, > I'm not a perfect programmer :) I understand that the error can't > actually contain the message because of all the exceptions throwing > exceptions thing. But here's a code snippet: > > try { > call_member<void>(self,"process",nowTime); > } catch ( const luabind::error& e ) { > const char* message = lua_tostring(e.state(), -1); > panicMessageBox(message); > } > > I did some searching on the mailing list and found a post related to > this same problem. The reply was: > > The reason we don't pass the actual message through the exception is > that we want to avoid heap allocations in our exception classes. Because > if that heap allocation would fail (i.e. if the exception class throws > another exception) the application would be terminated. > > The message is passed on the stack, you could do something like this: > > try > { > luabind::call_function<void>(L, "Foo"); > } > catch (const luabind::error& e) > { > const char* message = lua_tostring(e.state(), -1); > std::cout << message << "\n"; > } > > Which is exactly what I'm doing, but an "unhandled exception" still gets > thrown on the lua_tostring. Here's what the stack looks like in vs.net > when it crashes: > > > msvcr71d.dll!strlen() Line 78 Asm > msvcp71d.dll!std::char_traits<char>::length(const char * > _First=0x00000000) Line 442 + 0x9 C++ > > msvcp71d.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::assign(const char * _Ptr=0x00000000) Line 622 + 0x9 C++ > > msvcp71d.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> > >::basic_string<char,std::char_traits<char>,std::allocator<char> > >(const char * _Ptr=0x00000000) Line 363 C++ > tileDEBUG.exe!Object_wrapper::process(unsigned int nowTime=32) Line > 116 + 0x17 C++ > > So I'm not quite sure what's happening. The docs say not to access the > lua state after it has been destructed, but I don't see why it would > have been destructed before the catch. Any suggestions? > > -Kevin That callstack doesn't seem to point into any lua nor luabind code. Are you successfully catching the luabind exception? One thing you could try is to make sure e.state() == self, they should be. -- Arvid Norberg |