The Right Approach to Exceptions

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Feb 18 18:41:01 PST 2012


On 2/18/12 7:17 PM, H. S. Teoh wrote:
> 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*.

I agree that that was a design mistake, but it's easy to opt out the 
unnecessary part. All C++ applications I've worked with define exception 
hierarchies. In fact at Facebook we have a lint rule that prohibits 
throwing arbitrary stuff.

Andrei


More information about the Digitalmars-d mailing list