Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

core.exception

The exception module defines all system-level exceptions and provides a mechanism to alter system-level error handling.
Authors:
Sean Kelly and Jonathan M Davis
class RangeError: object.Error;
Thrown on a range error.
class ArrayIndexError: core.exception.RangeError;
Thrown when an out of bounds array index is accessed.
const size_t index;
Index into array
const size_t length;
Length of indexed array
class ArraySliceError: core.exception.RangeError;
Thrown when an out of bounds array slice is created
const size_t lower;
Lower/upper bound passed to slice: array[lower .. upper]
const size_t upper;
Lower/upper bound passed to slice: array[lower .. upper]
const size_t length;
Length of sliced array
class AssertError: object.Error;
Thrown on an assert error.
class FinalizeError: object.Error;
Thrown on finalize error.
class OutOfMemoryError: object.Error;
Thrown on an out of memory error.
class InvalidMemoryOperationError: object.Error;
Thrown on an invalid memory operation.
An invalid memory operation error occurs in circumstances when the garbage collector has detected an operation it cannot reliably handle. The default D GC is not re-entrant, so this can happen due to allocations done from within finalizers called during a garbage collection cycle.
class ForkError: object.Error;
Thrown on a configuration error.
class SwitchError: object.Error;
Thrown on a switch error.
class UnicodeException: object.Exception;
Thrown on a unicode conversion error.
alias AssertHandler = void function(string file, ulong line, string msg) nothrow;

nothrow @nogc @property @trusted AssertHandler assertHandler();

nothrow @nogc @property @trusted void assertHandler(AssertHandler handler);
Gets/sets assert hander. null means the default handler is used.
nothrow void onAssertError(string file = __FILE__, size_t line = __LINE__);
A callback for assert errors in D. The user-supplied assert handler will be called if one has been supplied, otherwise an AssertError will be thrown.
Parameters:
string file The name of the file that signaled this error.
size_t line The line number on which this error occurred.
nothrow void onAssertErrorMsg(string file, size_t line, string msg);
A callback for assert errors in D. The user-supplied assert handler will be called if one has been supplied, otherwise an AssertError will be thrown.
Parameters:
string file The name of the file that signaled this error.
size_t line The line number on which this error occurred.
string msg An error message supplied by the user.
nothrow void onUnittestErrorMsg(string file, size_t line, string msg);
A callback for unittest errors in D. The user-supplied unittest handler will be called if one has been supplied, otherwise the error will be written to stderr.
Parameters:
string file The name of the file that signaled this error.
size_t line The line number on which this error occurred.
string msg An error message supplied by the user.
pure nothrow @nogc @trusted noreturn onRangeError(string file = __FILE__, size_t line = __LINE__);
A callback for general array bounds errors in D. A RangeError will be thrown.
Parameters:
string file The name of the file that signaled this error.
size_t line The line number on which this error occurred.
Throws:
pure nothrow @nogc @trusted noreturn onArraySliceError(size_t lower = 0, size_t upper = 0, size_t length = 0, string file = __FILE__, size_t line = __LINE__);
A callback for array slice out of bounds errors in D.
Parameters:
size_t lower the lower bound of the index passed of a slice
size_t upper the upper bound of the index passed of a slice or the index if not a slice
size_t length length of the array
string file The name of the file that signaled this error.
size_t line The line number on which this error occurred.
pure nothrow @nogc @trusted noreturn onArrayIndexError(size_t index = 0, size_t length = 0, string file = __FILE__, size_t line = __LINE__);
A callback for array index out of bounds errors in D.
Parameters:
size_t index index in the array
size_t length length of the array
string file The name of the file that signaled this error.
size_t line The line number on which this error occurred.
nothrow @trusted noreturn onFinalizeError(TypeInfo info, Throwable e, string file = __FILE__, size_t line = __LINE__);
A callback for finalize errors in D. A FinalizeError will be thrown.
Parameters:
TypeInfo info The TypeInfo instance for the object that failed finalization.
Throwable e The exception thrown during finalization.
string file The name of the file that signaled this error.
size_t line The line number on which this error occurred.
Throws:
pure nothrow @nogc @trusted noreturn onOutOfMemoryError(void* pretend_sideffect = null, string file = __FILE__, size_t line = __LINE__);
A callback for out of memory errors in D. An OutOfMemoryError will be thrown.
pure nothrow @nogc @trusted noreturn onInvalidMemoryOperationError(void* pretend_sideffect = null, string file = __FILE__, size_t line = __LINE__);
A callback for invalid memory operations in D. An InvalidMemoryOperationError will be thrown.
pure nothrow @nogc @trusted noreturn onForkError(string file = __FILE__, size_t line = __LINE__);
A callback for errors in the case of a failed fork in D. A ForkError will be thrown.
Parameters:
string file The name of the file that signaled this error.
size_t line The line number on which this error occurred.
pure @safe noreturn onUnicodeError(string msg, size_t idx, string file = __FILE__, size_t line = __LINE__);
A callback for unicode errors in D. A UnicodeException will be thrown.
Parameters:
string msg Information about the error.
size_t idx String index where this error was detected.
string file The name of the file that signaled this error.
size_t line The line number on which this error occurred.
void _d_assertp(immutable(char)* file, uint line);
These functions must be defined for any D program linked against this library.
Function calls to these are generated by the compiler and inserted into the object code.
void _d_assert_msg(string msg, string file, uint line);
These functions must be defined for any D program linked against this library.
Function calls to these are generated by the compiler and inserted into the object code.
void _d_assert(string file, uint line);
These functions must be defined for any D program linked against this library.
Function calls to these are generated by the compiler and inserted into the object code.
void _d_unittestp(immutable(char)* file, uint line);
These functions must be defined for any D program linked against this library.
Function calls to these are generated by the compiler and inserted into the object code.
void _d_unittest_msg(string msg, string file, uint line);
These functions must be defined for any D program linked against this library.
Function calls to these are generated by the compiler and inserted into the object code.
void _d_unittest(string file, uint line);
These functions must be defined for any D program linked against this library.
Function calls to these are generated by the compiler and inserted into the object code.
void _d_arrayboundsp(immutable(char*) file, uint line);
Called when an invalid array index/slice or associative array key is accessed
These functions must be defined for any D program linked against this library.
Function calls to these are generated by the compiler and inserted into the object code.
void _d_arraybounds(string file, uint line);
ditto
These functions must be defined for any D program linked against this library.
Function calls to these are generated by the compiler and inserted into the object code.
void _d_arraybounds_slicep(immutable(char*) file, uint line, size_t lower, size_t upper, size_t length);
Called when an out of range slice of an array is created
These functions must be defined for any D program linked against this library.
Function calls to these are generated by the compiler and inserted into the object code.
void _d_arraybounds_slice(string file, uint line, size_t lower, size_t upper, size_t length);
ditto
These functions must be defined for any D program linked against this library.
Function calls to these are generated by the compiler and inserted into the object code.
void _d_arraybounds_indexp(immutable(char*) file, uint line, size_t index, size_t length);
Called when an out of range array index is accessed
These functions must be defined for any D program linked against this library.
Function calls to these are generated by the compiler and inserted into the object code.
void _d_arraybounds_index(string file, uint line, size_t index, size_t length);
ditto
These functions must be defined for any D program linked against this library.
Function calls to these are generated by the compiler and inserted into the object code.