This module defines functions related to exceptions and general error
handling. It also defines functions intended to aid in unit testing.
Synopsis of some of std.exception's functions:
string synopsis()
{
FILE* f = enforce(fopen("some/file"));
// f is not null from here on
FILE* g = enforce!WriteException(fopen("some/other/file", "w"));
// g is not null from here on
Exception e = collectException(write(g, readln(f)));
if (e)
{
... an exception occurred...
... We have the exception to play around with...
}
string msg = collectExceptionMsg(write(g, readln(f)));
if (msg)
{
... an exception occurred...
... We have the message from the exception but not the exception...
}
char[] line;
enforce(readln(f, line));
return assumeUnique(line);
}
Asserts that the given expression does not throw the given type
of Throwable. If a Throwable of the given type is thrown,
it is caught and does not escape assertNotThrown. Rather, an
AssertError is thrown. However, any other Throwables will escape.
Asserts that the given expression throws the given type of Throwable.
The Throwable is caught and does not escape assertThrown. However,
any other Throwables will escape, and if no Throwable
of the given type is thrown, then an AssertError is thrown.
Casts a mutable array to an immutable array in an idiomatic
manner. Technically, assumeUnique just inserts a cast,
but its name documents assumptions on the part of the
caller. assumeUnique(arr) should only be called when
there are no more active mutable aliases to elements of arr. To strengthen this assumption, assumeUnique(arr)
also clears arr before returning. Essentially assumeUnique(arr) indicates commitment from the caller that there
is no more mutable access to any of arr's elements
(transitively), and that all future accesses will be done through
the immutable array returned by assumeUnique.
Catches and returns the exception thrown from the given expression.
If no exception is thrown, then null is returned and result is
set to the result of the expression.
Catches the exception thrown from the given expression and returns the
msg property of that exception. If no exception is thrown, then null is
returned. E can be void.
ML-style functional exception handling. Runs the supplied expression and
returns its result. If the expression throws a Throwable, runs the
supplied error handler instead and return its result. The error handler's
type must be the same as the expression's type.
This enum is used to select the primitives of the range to handle by the
handle range wrapper. The values of the enum can be OR'd to
select multiple primitives to be handled.
If !value is false, value is returned. Otherwise,
new E(msg, file, line) is thrown. Or if E doesn't take a message
and can be constructed with new E(file, line), then
new E(file, line) will be thrown.