J
James Kanze
[...]
I think that there are system level exceptions which should be
considered "part of the contract" unless explicitly specified
otherwise. Things like std::bad_alloc, for example. The usual
rule is to document exceptions I guarantee to throw, along with
the conditions under which I guarantee to throw them, and to
document the cases where I guarantee to not even throw "system"
exceptions. Most functions, however, say nothing about things
like std::bad_alloc in their explicit contract. (They might,
however, say something like "throw()": the function guarantes to
throw no exceptions whatever, not even system level exceptions.)
FWIW: I find very little use for exceptions other than system
level exceptions, except in special cases like constructors (or
some functions which return objects, particularly overloaded
operators). But that may just be related to my application
domains.
Any exception that is thrown _should_ specified in the
contract. Otherwise, why should a caller provide a catch()
clause? Uncaught exceptions are more or less equivalent to
asserts in that they unwinde the stack completely.
I think that there are system level exceptions which should be
considered "part of the contract" unless explicitly specified
otherwise. Things like std::bad_alloc, for example. The usual
rule is to document exceptions I guarantee to throw, along with
the conditions under which I guarantee to throw them, and to
document the cases where I guarantee to not even throw "system"
exceptions. Most functions, however, say nothing about things
like std::bad_alloc in their explicit contract. (They might,
however, say something like "throw()": the function guarantes to
throw no exceptions whatever, not even system level exceptions.)
FWIW: I find very little use for exceptions other than system
level exceptions, except in special cases like constructors (or
some functions which return objects, particularly overloaded
operators). But that may just be related to my application
domains.