// File: aptest2.cpp // #include "Fred.h" #include using namespace std ; void foobar() { cout << "Entering foobar()\n" ; auto_ptr Fptr7(new Fred(17)), Fptr8(new Fred(12)) ; auto_ptr Fptr3(new Fred(9)) ; try { throw "a perfect spiral" ; } catch(const char* str) { cout << "Caught exeption in foobar()\n" ; throw ; // rethrow } cout << "Exiting foobar()\n" ; } main() { { // Local scope 1 cout << "Entering local scpe 1\n" ; auto_ptr Fptr1(new Fred(5)) ; auto_ptr Fptr2 ; Fptr2 = Fptr1 ; // change ownership Fptr2->print() ; cout << "Exiting local scpe 1\n" ; } // End of Local scope 1 { // Local scope 2 cout << "Entering local scpe 2\n" ; try { foobar() ; } catch (const char * str) { cout << "Exception handler in main():" ; cout << str << endl ; } } // End of Local scope 2 }