First page Back Continue Last page Graphics

fig13_01.cpp (3 of 3)

  • 47 // enable user to enter two integers to divide
  • 48 while ( cin >> number1 >> number2 ) {
  • 49
  • 50 // try block contains code that might throw exception
  • 51 // and code that should not execute if an exception occurs
  • 52 try {
  • 53 result = quotient( number1, number2 );
  • 54 cout << "The quotient is: " << result << endl;
  • 55
  • 56 } // end try
  • 57
  • 58 // exception handler handles a divide-by-zero exception
  • 59 catch ( DivideByZeroException &divideByZeroException ) {
  • 60 cout << "Exception occurred: "
  • 61 << divideByZeroException.what() << endl;
  • 62
  • 63 } // end catch
  • 64
  • 65 cout << "\nEnter two integers (end-of-file to end): ";
  • 66
  • 67 } // end while
  • 68
  • 69 cout << endl;
  • 70
  • 71 return 0; // terminate normally
  • 72
  • 73 } // end main