The OpenD Programming Language

basicExceptionCtors

Convenience mixin for trivially sub-classing exceptions

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.

Constructors

this
this(string msg, string file, size_t line, Throwable next)
this
this(string msg, Throwable next, string file, size_t line)

Examples

class MeaCulpa: Exception
{
    ///
    mixin basicExceptionCtors;
}

try
    throw new MeaCulpa("test");
catch (MeaCulpa e)
{
    assert(e.msg == "test");
    assert(e.file == __FILE__);
    assert(e.line == __LINE__ - 5);
}

Meta