Let's improve D's exceptions
Adam D. Ruppe via Digitalmars-d
digitalmars-d at puremagic.com
Fri May 15 06:20:11 PDT 2015
On Friday, 15 May 2015 at 09:23:12 UTC, Jacob Carlborg wrote:
> So why isn't data members used more, because of the boilerplate
> to create a new subcalss?
Yeah, I think so. A new exception subclass has to write out the
long constructor signature, forward it, add the data members,
write code to set them, and at least write code to add them to
the toString (which itself has a long signature and needs a lot
of string formatting tedium).
That's a fair amount of code to write, especially compared to new
Exception("foo " ~ to!string(value)) right there inline when it
comes up.
But with reflection we can really simplify it to the point where
writing class Foo : Exception { int value; mixin ExtendException;
} becomes less of a hassle, or we could even extend a hierarchy
right inline like raise!SomeException(variadic, arguments).
More information about the Digitalmars-d
mailing list