lights FAQ Forum github.com/luapower/errors
This package
errors

Standard Libraries
glue
pp
oo
events
coro
errors
lpeg

errors

Structured exceptions for Lua


local errors = require'errors'

This is an API that adds structured exceptions to Lua. Exceptions, like coroutines are not used very frequently in Lua because they solve cross-cutting concerns(*) that don’t appear very often in code. But when they do appear, these devices are invaluable code decluttering tools.

Structured exceptions are an enhancement over string exceptions that enable selective catching and allow providing a context for the failure to help with recovery or logging.

(*) Coroutines address the problem of inversion-of-control head-on. Exceptions address the problem of recoverable failure head-on, so they’re most useful in network I/O contexts.

API

error.error base class for errors
error.errortype([classname], [super]) -> eclass create an error class
eclass(...) -> e create an error object
error.new(classname, [e], ... | e) -> e create/wrap/pass-through an error object
error.is(v[, classes]) -> t|f check an error object type
error.raise(classname,... | e) (create and) raise an error
error.catch(classes, f, ...) -> t,... | f,e pcall f and catch errors
error.pcall(f, ...) -> ... pcall that stores traceback in e.traceback
error.check(v, ...) -> v | raise(...) assert with specifying an error class
error.protect(classes, f) -> protected_f turn raising f into a nil,e function
eclass:__call(...) -> e error class constructor
eclass:__tostring() -> s to make error(e) work
e.message formatted error message
e.traceback traceback at error site

In the API classes can be given as 'classname1 ...' or {class1->true}. When in table form, you must include all the superclasses in the table as they are not added automatically!


Last updated: 4 days ago | Edit on GitHub

Package:errors
Pkg type:Lua
Version: 71619f9
Last commit:
Author: Cosmin Apreutesei
License: Public Domain

Requires: none

Required by: none


Top