KK> If a function has an exception list specified, and it throws an
KK> exception not on the list, unexpected() will be called. But if the
KK> function has no exception specification, any thrown exception will be
KK> passed back to the caller, and if the caller can't catch it, to the
KK> caller's caller, etc. Right?
I'm no expert on C++'s implemenation of exceptions, but here's
the gist:
Exception handling is passing the buck: you allow errors to
be handled by the caller (or the caller of the caller).
A dirty example is the following.
IOClass io;
int i;
try { io.read >> i; } catch (...) { cout << "Exception caught\n";}
try { io.write << i; } catch (...) ( cout << "Exception caught\n";}
// Assuming that io.read/write are designed to throw and exception
// Yes, you could have had just
// try {io.read >> i; io.write << i;}.
Java has a very good implementation of exceptions. It is an error
not to handle an exception (or declare exceptions will be re-thrown).
You might want to look for a Java example to help expain C++'s use.
--- GEcho 1.00
---------------
* Origin: Digital OnLine Magazine! - (409)838-8237 (1:3811/350)
|