Recovery from an exception/error state

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Recovery from an exception/error state

Josh Green-3
Hi everyone,

I was wondering how everyone else is handling luabind::error's?

The way I understand it is:

If a luabind::error is thrown, then the lua_state's stack has been
unwound and placed an error message on the stack for us to do something
Once we have printed this error message(or not) then we are free to
continue with the application as if nothing happened.

If a panic function was called, then the lua_state is now invalid, and
there isn't much to be done that can recover from this.
(This is usually the result of an issue the programmer has made and
should be fixed anyway, so termination of the program should be

Could someone please tell me if I'm understanding this right?

Now, I was hoping to write a function like....
object callProtected(lua_state* lua,object environment, object function,
obj args){
  }catch(the nasties){

But this wouldn't suit my requirements as I would like to call this
function with arbitrary length of arguments.
Does anyone know how I would write such a function to encapsulate all
lua function calls so that any errors that are generated will
Caught and dealt with by my program?

I have had a look at the "luabind::set_error_callback" as an alternative
to the exception handling. This
Looked promising, but then I realised that the function specified wasn't
expected to return?!?!

Meaning the callback function should either longjump, generate it's own
exception, or terminate.
I'm not sure I understand why it would be necessary for this to be the
case.. By the end of the pcall inside luabind
If there was an error, then the lua stack has been unwound and has an
error message is waiting (ready to go again once the
Error message is removed -- SEE lua_pcall entry in lua 5.1 manual). So
why would we want to exit the program or throw an exception (of course
throwing an exception is an option, but it shouldn't be NECESSARY,

Another option I thought of was to write a macro perhaps...

#define HANDLE_EXCEPTION(e) printErrorString(e);
#define CATCH_LUA(exp)  try{exp}catch(luabind::error

Not sure if that would work or not.

I would like to see the ability for me to simply specify the callback
and allow the program to continue execution after the callback has
returned, I can't see any reason for this not to be allowed, could
someone please explain it to me?

How is everyone else handling this situation?

Thanks everyone


Take Surveys. Earn Cash. Influence the Future of IT
Join's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
luabind-user mailing list
[hidden email]