As with non-class types, the exception type can be specified as a reference to an ancestor type:
$ cat t.cc #include <iostream> struct red { }; struct mauve : red { }; int main() { try { throw mauve(); } catch (red) { std::cout << "caught a red.\n"; } try { throw mauve(); } catch (red &) { std::cout << "caught a red ref.\n"; } } $ g++ -o t -ansi -pedantic t.cc $ ./t caught a red. caught a red ref. $ CC -o t t.cc $ ./t caught a red. caught a red ref. $
This page last modified on 14 February 2004.