lua-users home
lua-l archive

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


2011/3/18 Daurnimator <quae@daurnimator.com>:
> xpcall does not handle ERRERR how it should.
> The error handler for the error handler is itself; not the upper scope
> as you would imagine.
>
> a=function() error("a") end
> b=function(e) print("b",e) end
> xpcall(a,b)
>
> This bug stops you from being able to bubble up errors.
>
> a = function() error{type="foo"} end
> xpcall(a,function(err) if err.type == "bar" then else error(err) end end)
>
> ==> you'd imagine that the error in the error handler would re-throw the error.

Unless your errors have to cross Lua-C boundaries, you can implement
such an exception filtering scheme with coroutines, by calling yield
(that you can rename) instead of error. In addition to blocking or
forwarding exceptions you could even recover from them (by resuming
the throw).