[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Binding C++ functions that 'throw' exceptions
- From: "RJP Computing" <rjpcomputing@...>
- Date: Fri, 17 Aug 2007 16:31:15 -0400
On 8/17/07, Thomas Breuel <email@example.com> wrote:
However, patching Lua is not an option for us; we're creating an open
source project, and we don't want to get into the business of
maintaining a Lua fork. If we need to patch anything, it can only be
the interface generator. Furthermore, any interface generator not
designed to cope with exceptions (i.e., most of them) may need to be
hacked anyway, even if Lua itself has exception handling, because
there may need to be cleanup in the interface code (deallocation of
I completely agree. I can't maintain a fork of Lua either. My group doesn't want that responsibility.
So, I think it would be great if the base Lua distribution were
updated to handle exceptions better. Basically, what would need to
be done is:
* When compiled with C++, there need to be 'extern "C"' wrapped
around all API function declarations.
* When compiled with C++, there should be try...catch blocks wrapped
around all calls to user functions.
* By default, both exception mechanisms should be enabled (for
compatibility), but users should be able to disable them with -
DLUA_NO_EXCEPTIONS and -DLUA_NO_SETJMP
This would maintain compatibility with the existing C distribution
and it would ensure that, no matter what exceptions get thrown, Lua
remains in a consistent state.
Yes, this sounds like a better solution than the present.
Then, interface generators that cope with C++ need to be reviewed for
whether they are exception-safe, and they can provide additional
facilities to deal with exceptions in a more intelligent way, such as
translating specific exceptions into specific Lua errors, etc.
Are you going to work on a solution for exceptions in toLua++? Do you want or need help? I need this fairly soon, so I was going to start working on toLua++ and add a hook that would simply convert the exception to a Lua error(). I know this is not enough, I just need to get moving and continue to make improvements as we go. What are your plans?
BTW, note that many existing libraries use exception hierarchies that
are not based on std::exception, so just catching std::exception is
not sufficient. The std::exception class is simply the base class for
exceptions in the standard library.
My entire library is written with a common exception class and it does _not_ derive from std::exception. I wish that it did, but it doesn't and it is a great little class that works well for the entire library.