Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-11-04 08:37:38


Alexander Terekhov wrote:
> "E. Gladyshev" wrote:
> [...]
>> Ok, when an exception happens, how do I use exception safety
>> techniques
>> in practice, can you give some *practical* examples with catch(...)?

The right question to ask is "how can I use something that doesn't provide
exception safety guarantees in practice?"

> They'll all work just fine as long as your program is "correct" (read:
> nothing unexpected can be thrown, each and every swallowed exception
> is really-really meant to be swallowed, stack overflow and all other
> "hardware exceptions" aren't meant to be catchable by "the C++ catch"
> and so forth). IOW, you're not supposed to ever have an "incorrect"
> program.

No. You _can_ have an incorrect program. It's just that exception safety
guarantees do not apply to it, but then again, no guarantees apply. There is
nothing special about exception safety guarantees in this regard. Consider
this simple example:

int f(int x);

// Returns: 2*x

In an incorrect program, you obviously can't rely on the return value being
2*x, or that f() doesn't have side effects; it doesn't matter whether an
exception is thrown or not.

Whether catch(...) is overloaded to catch particular manifestations of
undefined behavior is not directly relevant to this point.


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