box b(1, 2); // How can box::box() handle internal errors?
b1 = b1 + b2; // how can box::operator + () handle internal errors?
throw
, catch
, and try
throw
Statementthrow
statement lauches (throws) an exception.
throw
expr throws the value expr as an exception.
return
in syntax and semantics
catch
Statementcatch (
type-spec [ name ] ) {
body
}
- catches a thrown exception
catch(. . .) { }
catches any exception
try
Statementtry {
body }
catch-stmt . . .
catch
body, continue after
the try
try
is not the scope of a catch
main()
causes termination
catch
body is like any other
exception
<exception>
defines the virtual class exception
char * exception::what(void) const
<stdexcept>
defines some derived exceptions -
runtime_error
and logic_error
catch
handler can rethrow an exception using throw
throw
clause
throw (
ex1, ex2, . . . )
unexpected
exceptions
bad_alloc
in new
in
particular
new
- this used to be standard
auto_pointers
provide a means for automatic resource recovery on
exceptions
This page last modified on 22 November 2002.