#include #include class ExceptionTest { private: int var; public: ExceptionTest( bool doThrow ) { if ( doThrow ) { throw exception(); } var = 5; } int returnVar( bool doThrow ) { if ( doThrow ) { throw exception(); } return var; } }; int main() { ExceptionTest *exceptionTest = NULL; try { exceptionTest = new ExceptionTest( true ); cout << "ExceptionTest 1 did not throw\n"; } catch( exception e ) { cout << "ExceptionTest 1 Exception handled\n"; } if ( exceptionTest == NULL ) { cout << "ExceptionTest is NULL\n"; } try { exceptionTest = new ExceptionTest( false ); cout << "ExceptionTest 2 did not throw\n"; } catch( exception e ) { cout << "ExceptionTest 2 Exception handled\n"; } if ( exceptionTest == NULL ) { cout << "ExceptionTest is NULL\n"; } try { int result = exceptionTest->returnVar( true ); cout << "result = " << result << "\n"; } catch( exception e ) { cout << "returnVar() Exception handled\n"; } return 0; }