D 1.076 Alpha for Windows 64 bits, works with VS 2010
Nick Sabalausky
SeeWebsiteToContactMe at semitwist.com
Mon Oct 1 13:00:11 PDT 2012
On Mon, 01 Oct 2012 19:14:45 +0200
Jacob Carlborg <doob at me.com> wrote:
> On 2012-10-01 14:30, Nick Sabalausky wrote:
>
> > Haxe can throw anything, too. I've always found it borderline
> > useless, and frequently a pain.
>
> I find it quite annoying to have to create new classes for exceptions
> all the time. And since D constructors aren't inherited I need to
> also create a constructor that just forwards to the base class. Just
> useless boilerplate code.
>
If I'm being lazy, I'll just throw a normal Exception:
throw new Exception("Whatever happened");
So it's almost as convenient as throwing a string (just a little more
typing), but unlike throwing strings or other non-Exceptions, you still
get the benefits of:
1. Always having the benefits of Exception, such as a stack trace.
2. Never having to deal with, or even consider the possibility of,
"What if some stupid lib or callback decides to throw something
nonsensical like an int or a Widget?" And a "catch(Exception e)" (or
rather "catch(Error e)") will always catch everything. Some languages
have a "catch all, from any unspecified type", but then you can't
have have any way to access whatever was thrown (unless it's a dynamic
language).
But, what you said about Ruby is an interesting idea. Ie, that throwing
a string is really just sugar for throwing a normal exception. I didn't
know that about Ruby. It would be kinda neat if we could do:
throw "Shit happened";
And instead of actually throwing a string, it was just sugar for:
throw new Exception("Shit happened");
That'd be pretty cool.
On a related, but goofier, note:
http://semitwist.com/articles/article/view/stupid-coder-tricks-debugging-exception-handlers
More information about the Digitalmars-d-announce
mailing list