lua-users home
lua-l archive

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

> What precisely is a "chunk" then?


> But if an exception emanate from a Lua piece of code, I would like 
> to be able to handle it one way or another so the VM keeps running.


But please note that the execution of the piece of code that raises an
error is *always* aborted. There's no way around that. What you can do
is to protected the call that starts this piece of code.

On the other hand, you may set metamethods for catching things like
undefined variables or missing fields in tables, thus avoiding that
errors are raised in the first place.

> lua Main.lua
> If anything unexpected happens in Main.lua, the interpreter exits, 
> right? I would like to avoid this. How?

Avoid it how? For this example, you can do something like
	lua run.lua Main.lua
where run.lua does a pcall of loadfile(arg[1]) and handles errors as you please.

Bottom line: all mechanisms for error handling are there; it's up to the
application to use them to handle errors in suitable way for it. The
standalone Lua interpreter handles errors by printing an error message
and a stack trace and then quitting. (The only say you have on this is
that you may edit the error message before it's printed; just redefine
_TRACEBACK in 5.0 or debug.tracback int 5.1. However, it'll still quit.)