[Exceptional C++ Style] Item 12: Exception Safety: Is it Wort h it?

Kevlin Henney kevlin at curbralan.com
Fri Dec 3 06:50:12 EST 2004


In message <B1E1BF4A-44EA-11D9-9C89-0003938ABE50 at acm.org>, James Dennett 
<jdennett at acm.org> writes
>
>> The article suggests, nay states, that all code needs to be exception 
>>safe.
>> This only true where the application needs to carry on after an 
>>exception.
>> This depends on what exceptions are used for of course, but in my 
>>experience
>> they are used to report very bad things in libraries, and the 
>>application
>> tells the user and gives up. In that case it doesn't much matter if 
>>it  leaks
>> memory or other resources, or classes become unstable, because they 
>>are not
>> called any more.
>
>The conclusion doesn't follow if, as many applications do, you have
>persistent resources which won't be cleaned up by the OS.

Agreed. IIRC, there was an accu-general discussion on this a while back. 
I mentioned that I had tended to work with four categories not three, 
including the degenerate no-guarantee guarantee, but had expanded it to 
five based on some stuff that Andrew Koenig had written focusing on just 
this problem that you mention. There was some discussion about other 
possible categories, but these tended to be variations within a category 
rather than giving you a guarantee that you could program, recover or 
panic against.

The categories I am using are along the following lines:

(0) The no-guarantee guarantee
(1) The leak guarantee (close to the situation you are describing)
(2) The no-leak guarantee (aka basic or weak)
(3) The transactional guarantee (aka strong)
(4) The no-throw guarantee

(2) to (4) qualify as some form of exception safety and map to Herb and 
Dave Abrahams' guarantees, (1) is not exception safe but allows some 
grace in failure and (0) you can't run and you can't hide :-)

Kevlin
-- 
____________________________________________________________

   Kevlin Henney                   phone:  +44 117 942 2990
   mailto:kevlin at curbralan.com     mobile: +44 7801 073 508
   http://www.curbralan.com        fax:    +44 870 052 2289
   Curbralan: Consultancy + Training + Development + Review
____________________________________________________________



More information about the Effective-cpp mailing list