Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2002-08-19 03:23:03


Peter Dimov wrote:
>
> From: "Alexander Terekhov" <terekhov_at_[hidden]>
> >
> > BTW, some interesting thoughts on using exceptions to report rather
> > funny things can be found here:
> >
> > http://www.bleading-edge.com/Publications/C++Report/v9609/Column3.rtf
> > http://www.bleading-edge.com/Publications/C++Report/v9609/Column3.htm
> > (Exceptions and Debugging, Jack Reeves)
> >
> > http://www.bleading-edge.com/Publications/C++Report/v9703/Column5.rtf
> > http://www.bleading-edge.com/Publications/C++Report/v9703/Column5.htm
> > (Reflections on Exceptions and the STL, Jack Reeves):
>
> Indeed. Do you agree with the material in the articles?

Well, a few corner cases aside, I'd say that I DO ACCEPT it. (as just
yet another sign of our highly imperfect reality ;-) )

> This is the old
> "asserts or exceptions" argument; it's amazing how many people feel that the
> answer must be either "asserts" or "exceptions", when in fact the scenarios
> presented in the first article clearly show some obvious "assert"
> candidates, and some obvious "exception" candidates.

Yep. But consider that in the C++ standard itself you can find bits like:

"Violation of the preconditions specified in a function's Required
 behavior paragraph results in undefined behavior unless the function's
 Throws paragraph specifies throwing an exception when the precondition
 is violated."

"The class logic_error defines the type of objects thrown as exceptions
 to report errors presumably detectable before the program executes,
 such as violations of logical preconditions or class invariants."

Well, another funny thing that I've recently had a chance to enjoy was
the "pick the one you like best" DieDieDie() functions in the latest
Sutter's MXC++ book. Undefined behaviors abusing 0-things and "another
C-style method" calling explicitly good old abort() [it is currently
severely BROKEN in POSIX/IEEE Std 1003.1-2001, and the correction is
underway, BTW] aside, here's the "C++ ways" that he offers:

<quote>

 void DieDieDie() // unwind back to the last "catch(...)"
 {
   class LocalClass {};
   throw LocalClass();
 }

 void DieDieDie() // an alternative for standardistes
 {
   throw std::logic_error();
 }

</quote>

Well, to be fair, he also mentions [the LAST alternative "for
standardistes having good compilers"] sort of "The Right Thing":

<quote>

                  // for standardistes having good compilers
 void DieDieDie() throw()
 {
   throw 0;
 }

</quote>
 
So, as Sutter says on the same page: "You get the idea", I hope. ;-)

regards,
alexander.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk