lua-users home
lua-l archive

Re: Try-catch and try-finally

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


My somewhat unfinished version: https://github.com/mpeterv/goodcall
Pros:
* Supports Python's `else` block, which is executed only if `try` block
 didn't throw.
* Allows rethrowing without losing original traceback.
* Supports yielding from protected blocks a-la coxpcall, but unlike it
 doesn't lose tracebacks in any case.
Cons:
* Rethrown errors are tables {err, traceback}.
 If some errors are part of an API, users have to know how to check
 if an error is wrapped and how to unwrap it. Or they have to use my
module, too.
* Rethrown errors have __tostring metamethod to make them look nice
 when caught by something that just prints errors. Unfortunately, Lua
interpreters
 for different versions handle such table errors differently, with
Lua 5.1 replacing
 it with `(error object is not a string)`.
-- Peter

AltStyle によって変換されたページ (->オリジナル) /