Documentation
¶
Overview ¶
Package exn provides an exception-like mechanism.
It is a bit easier to reason about than standard exceptions, since not any code can throw, only code given access to a throw callback. See the docs for Try.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Try ¶
Try invokes f, which is a callback with type:
func(throw Thrower) T
Thrower is an alias for func(error, ...string).
If f returns normally, Try returns the value f returned and a nil error.
If f invokes throw with a non-nil error, f's execution is terminated, and Try returns the zero value for T and the error that was passed to throw.
If f invokes throw with a nil argument, throw returns normally without terminating f. This is so that error handling code can pass errors to throw unconditionally, like:
v, err := foo() throw(err)
f must not store throw or otherwise cause it to be invoked after Try returns.
Callers may pass additonal string arguments to throw, which will wrap the error with additional context, i.e. throw(err, "something") is equivalent to throw(Wrap("something", err))