lua-users home
lua-l archive

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




2011/2/19 Mike Pall <mikelu-1102@mike.de>
Siddon Tang wrote:
> catch(...)
> {
>   longjmp(buffer, 1);
> }

C++ exceptions and longjmp do not mix well on most platforms.

> If I use lua_error to throw a exception, the program will abort when second
> call DoFunc.

LuaJIT directly throws a low-level exception on x64. The catch()
opens a C++ exception handling context. But since you longjmp out
of it, it never gets closed. That's why it crashes next time.

> But when I use throw instead, all works fine.

It looks like C++ throw has special handling to avoid this and
resets the context. Alas, I can't do this with the low-level
exceptions used by LuaJIT (and I can't use C++ throw either).

> In the luajit extensions, it said "Throwing Lua errors across C++ frames is
> safe", maybe can't be used with longjmp at same time?

The problem is not mixing Lua errors and C++ exceptions. This
works fine on x64, because they use the same underlying mechanism.

But mixing longjmp with C++ exceptions is generally not
recommended. As we can see, there's a good reason for it.

--Mike



Well, Thank you very much!
I think I will not mix longjmp and c++ exception together.