lua-users home
lua-l archive

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

On Wed, Jan 13, 2010 at 11:49 PM, Nevin Flanagan <> wrote:
> Exception handling in particular is awkward, due to Lua's extremely limited selection of actual types. You could possibly use a construction like
> try errName do
>  code
> catch errExpr1 do
>  handler
> catch errExpr2 do
>  handler
> end
> where the various errExpr clauses would be evaluated in order with errName in scope as the value supplied to the triggering use of error(). But if the try block follows the usual conventions for blocks, we would lose the ability to pass back values that we have with pcall.

This doesn't really make sense for a dynamically typed language like
Lua. I've worked on a patch for Lua 5.1 to add try/catch and I ended
up with this construct:

catch <Name> do
] end

The catch block can determine what kind of error object in the
variable Name is and go from there. (For those curious I decided to
wait for 5.2 before finishing this patch due to the extensive changes
being made for C continuations.)

-Patrick Donnelly

"Let all men know thee, but no man know thee thoroughly: Men freely
ford that see the shallows."

- Benjamin Franklin