First page Back Continue Last page Graphics

fig13_03.cpp (2 of 2)

  • 24 // function1 invokes function2
  • 25 void function1() throw ( runtime_error )
  • 26 {
  • 27 function2(); // second
  • 28 }
  • 29
  • 30 // demonstrate stack unwinding
  • 31 int main()
  • 32 {
  • 33 // invoke function1
  • 34 try {
  • 35 function1(); // first
  • 36
  • 37 } // end try
  • 38
  • 39 // handle run-time error
  • 40 catch ( runtime_error &error ) // fifth
  • 41 {
  • 42 cout << "Exception occurred: " << error.what() << endl;
  • 43
  • 44 } // end catch
  • 45
  • 46 return 0;
  • 47
  • 48 } // end main