//: C01:Basexcpt.cpp // From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison. // (c) 1995-2004 MindView, Inc. All Rights Reserved. // See source code use permissions stated in the file 'License.txt', // distributed with the code package available at www.MindView.net. // Exception hierarchies. #include using namespace std; class X { public: class Trouble {}; class Small : public Trouble {}; class Big : public Trouble {}; void f() { throw Big(); } }; int main() { X x; try { x.f(); } catch(X::Trouble&) { cout << "caught Trouble" << endl; // Hidden by previous handler: } catch(X::Small&) { cout << "caught Small Trouble" << endl; } catch(X::Big&) { cout << "caught Big Trouble" << endl; } } ///:~