ReusableExceptionImplementation

Common code to implement reusable exception semantics - one that has mutable message buffer where message data gets stored to

Constructors

this
this(size_t size)

Constructs exception object with mutable buffer pre-allocated to length size and other fields kept invalid.

Public Imports

ocean.meta.types.Qualifiers
public import ocean.meta.types.Qualifiers;
ocean.core.Buffer
public import ocean.core.Buffer;
ocean.core.array.Mutation
public import ocean.core.array.Mutation;
ocean.text.convert.Formatter
public import ocean.text.convert.Formatter;
ocean.text.convert.Integer_tango
public import ocean.text.convert.Integer_tango;

Members

Functions

append
typeof(this) append(cstring msg)

Appends new substring to mutable exception message

append
typeof(this) append(long num, bool hex)

Appends an integer to mutable exception message

enforce
void enforce(T ok, cstring msg, istring file, long line)

Throws this instance if ok is false, 0 or null.

fmtAppend
typeof(this) fmtAppend(cstring fmt, Args args)

Appends formatted string

message
cstring message()
set
typeof(this) set(cstring msg, istring file, long line)

Sets exception information for this instance.

Variables

reused_msg
Buffer!(char) reused_msg;

Fields used instead of msg for mutable messages. Exception.msg has istring type thus can't be overwritten with new data

Examples

auto e = new SomeReusableException(100);

e.set("message");
test (e.message() == "message");
auto old_ptr = e.reused_msg[].ptr;

try
{
    ocean.core.Enforce.enforce(e, false, "immutable");
    assert (false);
}
catch (SomeReusableException) { }
test (e.message() == "immutable");

try
{
    e.enforce(false, "longer message");
}
catch (SomeReusableException) { }
test (e.message() == "longer message");
test (old_ptr is e.reused_msg[].ptr);

try
{
    e.badName("NAME", 42);
}
catch (SomeReusableException) { }
test (e.message() == "Wrong name (NAME) 0x2A 42");
test (old_ptr is e.reused_msg[].ptr);

Meta