lua-users home
lua-l archive

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


On Thu, Dec 20, 2012 at 10:46 AM, Philipp Kraus
<philipp.kraus@flashpixx.de> wrote:
> Hello,
>
> I'm working a short time with Lua and primary with the C API, so I would like to know something about the error handling.
> Does there anything exists like exception in Lua? Eg the Lua script calls a C/C++ function, on there C++ function an error
> occurs and the C++ function throws an exception, I can catch the exception but I don't stop the program, but I would send
> the error to the running Lua script, so the script can catch the error and deal with them.
>
> How can I handling errors on the Lua side?
>
> Thanks
>
> Phil

LuaJIT on most platforms integrates C++ exceptions with Lua errors, so
pcall() will catch a thrown exception, and try/catch will catch an
error() if it wasn't caught by pcall first. (I think.)

In vanilla Lua, you'll want to explicitly catch the C++ exception and
generate a call to lua_error.

/s/ Adam