lua-users home
lua-l archive

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


Am 21.12.2012 um 13:18 schrieb Roberto Ierusalimschy:

>>> 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?
>> 
>> [...]
>> 
>> In vanilla Lua, you'll want to explicitly catch the C++ exception and
>> generate a call to lua_error.
> 
> Or better yet, call lua_error in the first place (instead of throwing
> a C++ exception). In Lua, you can catch such errors with 'pcall'.


Can I catch this error on the Lua script? In my case a C++ call throws
an exception, I catch them with try-catch, push the error with lua_error to
the stack and the running script should be handle this error.

Phil