lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> Any time I see a catch(...), I start worrying

Agreed. If you look at the 5.1 code you'll see that Lua throws a
lua_longjmp*.  Therefore, I think that Lua should only catch a lua_longjmp*
and not a "...".  Any other exception thrown within luaD_rawrunprotected
should be considered a programming error.

As an alternative to my more generic patch (posted earlier), here is a very
small patch (untested) that I think addresses the (...) issue only:

#define LUAI_TRY(L,c,a)	\
		if ((c)->status == 0) 
			(c)->status = -1;
		// Serious design error. Implementers are required to
		// throw *only* lua_longjmp*.

		// At this point we have no idea if the Lua stack has
		// an error message on it, and we don't know if (c)->status
		// is valid. All bets are off.

		// Pick your action  :-)


-----Original Message-----
[] On Behalf Of Greg Falcon
Sent: Friday, March 24, 2006 2:56 PM
To: Lua list
Subject: Re: std::exception Interoperability

Any time I see a catch(...), I start worrying, so I'd love to get a
look at your improvements to the exception handling.

Greg F

On 3/24/06, Erik Cassel <> wrote:
> 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
> 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
> Since Lua now throws std::exception-derived objects I can catch and
> errors with a catch(std::exception&) clause. Moreover, if I decide *not*
> 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