Template std.exception.basicExceptionCtors
Convenience mixin for trivially sub-classing exceptions
template basicExceptionCtors
;
Even trivially sub-classing an exception involves writing boilerplate code
for the constructor to: 1) correctly pass in the source file and line number
the exception was thrown from; 2) be usable with enforce
which
expects exception constructors to take arguments in a fixed order. This
mixin provides that boilerplate code.
Note however that you need to mark the mixin line with at least a minimal (i.e. just ///) DDoc comment if you want the mixed-in constructors to be documented in the newly created Exception subclass.
Current limitation: Due to bug #11500, currently the constructors specified in this mixin cannot be overloaded with any other custom constructors. Thus this mixin can currently only be used when no such custom constructors need to be explicitly specified.
Contained Functions
Name | Description |
---|---|
this | |
this |
Example
class MeaCulpa: Exception
{
///
mixin basicExceptionCtors;
}
try
throw new MeaCulpa("test");
catch (MeaCulpa e)
{
writeln(e .msg); // "test"
writeln(e .file); // __FILE__
writeln(e .line); // __LINE__ - 5
}