Throw static exception - Re: std.experimental.allocator.make should throw on out-of-memory
Nick Treleaven via Digitalmars-d
digitalmars-d at puremagic.com
Thu Apr 21 05:45:52 PDT 2016
On Wednesday, 20 April 2016 at 19:32:01 UTC, Basile Burg wrote:
> a system exist to throw @nogc exceptions that would work in
> this case (the message doesn't have to be customized so it can
> be static):
>
> @nogc @safe
> void throwStaticEx(T, string file = __FILE__, size_t line =
> __LINE__)()
> {
> static const e = new T(file, line);
> throw e;
> }
Nice idea, I tweaked it a bit to accept custom arguments to T
e.g. a message:
http://dpaste.dzfl.pl/5e58c0142ccd
throw staticEx!(Exception, "Look ma, @nogc exception!");
That works, but I couldn't get the staticEx(string msg) overload
to compile. Anyway, maybe something like this could go in
std.exception?
More information about the Digitalmars-d
mailing list