Report a bug
If you spot a problem with this page, click here to create a Github 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.

mir.exception

@nogc exceptions and errors definitions.
Most of API Required DIP1008.
class MirException: object.Exception;
Examples:
Generic style
import mir.exception;
try throw new MirException("Hi D", 2, "!");
catch(Exception e) assert(e.msg == "Hi D2!");
Examples:
C++ style
import mir.exception;
import mir.format;
try throw new MirException(stringBuf() << "Hi D" << 2 << "!" << getData);
catch(Exception e) assert(e.msg == "Hi D2!");
Examples:
Low-level style
import mir.exception;
import mir.format;
stringBuf buf;
try throw new MirException(buf.print( "Hi D", 2, "!").data);
catch(Exception e) assert(e.msg == "Hi D2!");
Examples:
@safe pure nothrow @nogc 
bool func(scope const(char)[] msg)
{
    /// scope messages are copied
    try throw new MirException(msg);
    catch(Exception e) assert(e.msg == msg);

    /// immutable strings are not copied
    static immutable char[] gmsg = "global msg";
    try throw new MirException(gmsg);
    catch(Exception e) assert(e.msg is gmsg);

    return __ctfe;
}

assert(func("runtime-time check") == 0);

static assert(func("compile-time check") == 1);
pure nothrow @nogc @safe this(scope const(char)[] msg, string file = __FILE__, size_t line = __LINE__, Throwable nextInChain = null);

pure nothrow @nogc @safe this(scope const(char)[] msg, Throwable nextInChain, string file = __FILE__, size_t line = __LINE__);

pure nothrow @nogc @safe this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable nextInChain = null);

pure nothrow @nogc @safe this(string msg, Throwable nextInChain, string file = __FILE__, size_t line = __LINE__);
Parameters:
const(char)[] msg message. No-scope msg is assumed to have the same lifetime as the throwable. scope strings are copied to internal buffer.
string file file name, zero terminated global string
size_t line line number
Throwable nextInChain next exception in the chain (optional)
pure nothrow @nogc @safe this(Args...)(auto ref scope Args args, string file = __FILE__, size_t line = __LINE__, Throwable nextInChain = null)
if (Args.length > 1);
Generic multiargument overload. Constructs a string using the print function.
ref @trusted auto enforce(string fmt, string file = __FILE__, int line = __LINE__, Expr)(auto return ref scope Expr arg);
Examples:
import mir.exception;
try enforce!"Msg"(false);
catch(Exception e) assert(e.msg == "Msg");
class MirError: object.Error;
Examples:
@system pure nothrow @nogc 
bool func(scope const(char)[] msg)
{
    /// scope messages are copied
    try throw new MirException(msg);
    catch(Exception e) assert(e.msg == msg);

    /// immutable strings are not copied
    static immutable char[] gmsg = "global msg";
    try throw new MirError(gmsg);
    catch(Error e) assert(e.msg is gmsg);

    return __ctfe;
}

assert(func("runtime-time check") == 0);

static assert(func("compile-time check") == 1);
pure nothrow @nogc @safe this(scope const(char)[] msg, string file = __FILE__, size_t line = __LINE__, Throwable nextInChain = null);

pure nothrow @nogc @safe this(scope const(char)[] msg, Throwable nextInChain, string file = __FILE__, size_t line = __LINE__);

pure nothrow @nogc @safe this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable nextInChain = null);

pure nothrow @nogc @safe this(string msg, Throwable nextInChain, string file = __FILE__, size_t line = __LINE__);
Parameters:
const(char)[] msg message. No-scope msg is assumed to have the same lifetime as the throwable. scope strings are copied to internal buffer.
string file file name, zero terminated global string
size_t line line number
Throwable nextInChain next exception in the chain (optional)
pure nothrow @nogc @safe this(Args...)(auto ref scope Args args, string file = __FILE__, size_t line = __LINE__, Throwable nextInChain = null)
if (Args.length > 1);
Generic multiargument overload. Constructs a string using the print function.
template MirThrowableImpl()
pure nothrow @nogc @safe this(scope const(char)[] msg, string file = __FILE__, size_t line = __LINE__, Throwable nextInChain = null);

pure nothrow @nogc @safe this(scope const(char)[] msg, Throwable nextInChain, string file = __FILE__, size_t line = __LINE__);

pure nothrow @nogc @safe this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable nextInChain = null);

pure nothrow @nogc @safe this(string msg, Throwable nextInChain, string file = __FILE__, size_t line = __LINE__);
Parameters:
const(char)[] msg message. No-scope msg is assumed to have the same lifetime as the throwable. scope strings are copied to internal buffer.
string file file name, zero terminated global string
size_t line line number
Throwable nextInChain next exception in the chain (optional)
pure nothrow @nogc @safe this(Args...)(auto ref scope Args args, string file = __FILE__, size_t line = __LINE__, Throwable nextInChain = null)
if (Args.length > 1);
Generic multiargument overload. Constructs a string using the print function.