diff --git a/error_handling.html b/error_handling.html index f1bb7a7..4964af0 100644 --- a/error_handling.html +++ b/error_handling.html @@ -58,12 +58,40 @@
std::exception
. Except in *very*
- rare circumstances where you can't afford the cost of a virtual table,
+ std::exception
. Except in *very* rare
+ circumstances where you can't afford the cost of a virtual
+ table,
std::exception
makes a reasonable exception base class,
and when used universally, allows programmers to catch "everything"
without resorting to catch(...)
. For more about
- catch(...)
, see below.catch(...)
, see below.
+
+ +#include <iostream> +struct my_exc1 : std::exception { char const* what() throw(); }; +struct my_exc2 : std::exception { char const* what() throw(); }; +struct your_exc3 : my_exc1, my_exc2 {}; + +int main() +{ + try { throw your_exc3(); } + catch(std::exception const& e) {} + catch(...) { std::cout << "whoops!" << std::endl; } +} ++ +The program above prints
"whoops"
because the
+C++ runtime can't resolve which exception
instance to
+match in the first catch clause.
+
+