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

David Sykes d.sykes at pindar.com
Wed Dec 1 03:39:06 EST 2004




> -----Original Message-----
> From: Herb Sutter [mailto:hsutter at microsoft.com]
> Sent: 30 November 2004 15:59
> To: effective-cpp at accu.org
> Subject: RE: [Exceptional C++ Style] Fw: Item 11: Try and Catch Me
> 
> 
> 
> In the above code, what happens if open fails? Can the function still
> succeed, perhaps in some degraded mode. For example, if the open is
> trying to open an Employee file that the function is supposed to
> summarize, then failure to open is clearly an error -- we can't create
> the summary if we can't read the file. But if the open is 
> trying to open
> a nonessential secondary file (e.g., some instrumentation output) or a
> file that might or might not be there and isn't essential to the
> processing, that's not an error if the function can still achieve its
> advertised postconditions.
> 
> Step 2 is to note that exceptions should be used to report errors. :-)
> See C++CS Item 72 for the exceptions to this rule, such as module
> boundaries.
> 
> Herb
> 
> 


Nice marketing! I shall check it out :)

It seems to me, then, that the open routine cannot tell if the file is
essential or secondary, and so can't know whether to throw an exception or
not.
If, as has been suggested, there was an exception and non exception method
then the caller could choose. Having the constructor throw an exception and
open return fail value would fit the guidelines of exceptions being good for
constructors and return values emitted by operations that can.


David Sykes
[ *** LongSig auto truncated *** ]

--- StripMime Report -- processed MIME parts ---
multipart/alternative
  text/plain (text body -- kept)
---



More information about the Effective-cpp mailing list