Thinking in C++ Vol 2 - Practical Programming |
Prev |
Home |
Next |
You may feel that the existing exception specification rules
aren t very safe, and that
should mean that no exceptions are thrown from this
function. If the programmer wants to throw any type of exception, you might
think he or she should have to say
void f() throw(...); // Not in C++
This would surely be an improvement because function
declarations would be more explicit. Unfortunately, you can t always know by
looking at the code in a function whether an exception will be thrown it could
happen because of a memory allocation, for example. Worse, existing functions
written before exception handling was introduced into the language may find
themselves inadvertently throwing exceptions because of the functions they call
(which might be linked into new, exception-throwing versions). Hence, the
uninformative situation whereby
means, Maybe I ll throw an exception, maybe I won t. This
ambiguity is necessary to avoid hindering code evolution. If you want to
specify that f throws no exceptions, use the empty list, as in:
Thinking in C++ Vol 2 - Practical Programming |
Prev |
Home |
Next |