lua-users home
lua-l archive

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


On Thu, 20 Sep 2018 00:12:21 +0200
nobody <nobody+lua-list@afra-berlin.de> wrote:

> From the user code, you call `hopefully( desc, params... )` (could also be
> hidden inside some constructor) and if the action fails, that tries
> the handlers in order (with the stack still intact – so this is a
> normal function, no language support needed etc.).

I'm not sure I understand how it's implemented -- can you somehow
protect a Lua call in such a way that your handler gets executed
at the same place in the stack where the original error() happened? --
but the R language has a similar construct: the tryCatch function.

R imitates pass-by-value semantics for all function arguments by using
lazy evaluation and copy-on-write, so an expression that gets passed to
a function isn't actually evaluated until the function uses it.
tryCatch() employs that and a few more tricks to intervene when the
expression being evaluated calls stop() and to call a matching handler
instead (if it has one supplied).

-- 
Best regards,
Ivan