View source code
Display the source code in object.d from which this page was generated on github.
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 local clone.

Class object.Exception

The base class of all errors that are safe to catch and handle.

In principle, only thrown objects derived from this class are safe to catch inside a catch block. Thrown objects not derived from Exception represent runtime errors that should not be caught, as certain runtime guarantees may not hold, making it unsafe to continue program execution.

Inherits from


Name Description
this Creates a new instance of Exception. The next parameter is used internally and should always be null when passed by user code. This constructor does not automatically throw the newly-created Exception; the throw statement should be used for that purpose.


Name Type Description
file string The file name of the D source code corresponding with where the error was thrown from.
info object.Throwable.TraceInfo The stack trace of where the error happened. This is an opaque object that can either be converted to string, or iterated over with foreach to extract the items in the stack trace (as strings).
line ulong The line number of the D source code corresponding with where the error was thrown from.
msg string A message describing the error.
next Throwable A reference to the next error in the list. This is used when a new Throwable is thrown from inside a catch block. The originally caught Exception will be chained to the new Throwable via this field.


Name Description
factory Create instance of class specified by the fully qualified name classname. The class must either have no constructors or have a default constructor.
message Get the message describing the error. Base behavior is to return the Throwable.msg field. Override to return some other error message.
opCmp Compare with another Object obj.
opEquals Test whether this is equal to o. The default implementation only compares by identity (using the is operator). Generally, overrides for opEquals should attempt to compare objects by their contents.
toHash Compute hash function for Object.
toString Overrides Object.toString and returns the error message. Internally this forwards to the toString overload that takes a sink delegate.
toString The Throwable hierarchy uses a toString overload that takes a sink delegate to avoid GC allocations, which cannot be performed in certain error situations. Override this toString method to customize the error message.


Walter Bright, Sean Kelly


Boost License 1.0.