The Right Approach to Exceptions

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Feb 18 17:17:12 PST 2012


On Sat, Feb 18, 2012 at 04:28:25PM -0800, Jonathan M Davis wrote:
[...]
> C++ is a horrible example of how exceptions should be done, so if
> you're basing what you want off of that, then that makes me think that
> you should be better familiar with how other, more recent languages
> use them (though maybe you're quite familiar with how C# and/or Java
> use Exceptions, I don't know).  From using Java, I think that how it
> handles exceptions in general is _far_ superior to how they're
> frequently dealt with in C++ (though that does tend to depend on who's
> doing the developing, since you _can_ have a decent exception
> hierarchy in C++).
[...]

The basic problem with C++ exceptions is that it allows you to throw
literally *anything*. Which is nice and generous, but not having a
common root to all exceptions cripples the system, because there is no
functionality that can be depended upon, like toString when what you
want is an error message.

Furthermore, not having a properly designed skeletal hierarchy to
inherit from also adds to the problem. With no existing standard
hierarchy to serve as a reference point, library writers just invent
their own systems, most of which don't interoperate properly with each
other. And thus the mess that is the C++ exception hierarchy.

I certainly hope D can do better than that.


T

-- 
If Java had true garbage collection, most programs would delete themselves upon execution. -- Robert Sewell


More information about the Digitalmars-d mailing list