Condition System
Rather than traditional exceptions, Atomy sports a condition/restart system modeled on Common Lisp's design. The native Ruby exception handling is available, but conditions and restarts are much more flexible.
Conditions
Condition: Error(@backtrace): SimpleError(@value) ExceptionError(@exception) NoRestartError(@name) PortError(@port): EndOfFile Warning(@backtrace): SimpleWarning(@value)
Condition system hierarchy. You should subclass one of these to create your own conditions.
Condition name => String
Get the name of a condition. By default, this will be the class name, but you may override this for your own behaviour.
Handling
Invoke the name
restart, passing args
along to its callback.
See with-restarts
.
{ ~*body } bind: ~*handlers
Register handlers
for various signals for the duration of body
's
execution.
The result is the result of body
.
with-restarts(~*restarts): ~*body
Register restarts available for the duration of body
's execution.
The restarts
should be in the form of
name(*args) -> expr
.
The result is the result of body
.
Signalling
signal(c) => any
Signal a value through all bound handlers, nearest-first, stopping when a restart is invoked.
error(x) => _
Like signal
, except that if no restart is invoked, the current
^debugger
is started.
If the given value is not an Error
, it is wrapped in a
SimpleError
. If the value is a Ruby Exception
, it is wrapped
in an ExceptionError
.
warning(x) => nil
Like signal
, except that if no restart is invoked, the warning is
printed to ^error-port
.
If the given value is not a Warning
, it is wrapped in a
SimpleWarning
. Warning messages can be muffled by binding for
Warning
and invoking the .muffle-warning
restart.
Debuggers
The default debugger. This will show the condition name, its message, and let the user pick from the available restarts.
DefaultDebugger run(condition) => _
Show the condition message and list the current available restarts, asking which one to invoke.
Debugger = dynamic(DefaultDebugger)
The current debugger. run
will be called with the condition as an
argument.