[Exceptional C++ Style] Fw: Item 11: Try and Catch Me

Terje Slettebø tslettebo at broadpark.no
Wed Dec 1 04:25:12 EST 2004


> Herb Sutter <hsutter at microsoft.com>:

> >I have to admit that I don't recall such recommendation even from my
> >earliest encounters with exceptions. The recommendations I saw were
> more
> >along the lines of the following:
> >
> >- If you can handle it: catch it.
> >- If you can't handle it but your caller might know something about how
> >to: leave it.
> >- If you can't handle it and your caller won't (or shouldn't) know the
> >exception type: translate it into something they'll understand.
> 
> Right. An example of the third is when a class's implementation catches
> a basic exception (e.g., bad_alloc) to one with higher-level semantics
> that makes sense in the context of the class (e.g., CannotOpenDialog).

One problem with some implementations of error condition translations (whether
they are error codes, exceptions, or what), is that they loose too much
information. I find it rather senseless to get an error something like (very
common, at least on Windows):

"File doesn't exist, is read-only, or not enough disk space."

I mean, come on, you're the computer; you tell me: Doesn't it exist, is it
read-only, or isn't there enough disk space? Am I supposed to guess, here?

Same with:

"Can't delete file because it may be in use."

"May"?! Come on... You know it better than me. Could you also tell me _what_ is
using it, so I may be able to release the file lock?

Regards,

Terje



More information about the Effective-cpp mailing list