[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: std::exception Interoperability
- From: "Erik Cassel" <erik@...>
- Date: Fri, 24 Mar 2006 11:15:18 -0800
I have patched Lua 5.1 to seamlessly work with std::exception.
This lets me throw an std::exception-derived object from anywhere in C++
code. Lua will catch it and translate it appropriately in
luaD_rawrunprotected().
Also, Lua uses an std::exception-derived class to throw Lua errors. This
means I can catch errors thrown by Lua (as in lua_touserdata).
The benefits of this approach are:
1) I don't have to write exception handlers in every entry point in my
code. If my code is based on std/boost then I can be confident that
exceptions thrown by my code will be handled by Lua. I don't have to
translate them into lua_error() calls.
2) It is perfectly safe for me to intercept an exception thrown by Lua.
Since Lua now throws std::exception-derived objects I can catch and inspect
errors with a catch(std::exception&) clause. Moreover, if I decide *not* to
re-throw the exception, then Lua automatically pops the error message from
the stack.
Has anybody else done something like this? Would it be useful to anybody?
Have I missed something?
I'd be happy to post my patch (and go over implementation details) and/or
show some sample code of how it can be used.
-Erik