First page Back Continue Last page Graphics

fig13_01.cpp (1 of 3)

  • 1 // Fig. 13.1: fig13_01.cpp
  • 2 // A simple exception-handling example that checks for
  • 3 // divide-by-zero exceptions.
  • 4 #include <iostream>
  • 5
  • 6 using std::cout;
  • 7 using std::cin;
  • 8 using std::endl;
  • 9
  • 10 #include <exception>
  • 11
  • 12 using std::exception;
  • 13
  • 14 // DivideByZeroException objects should be thrown by functions
  • 15 // upon detecting division-by-zero exceptions
  • 16 class DivideByZeroException : public exception {
  • 17
  • 18 public:
  • 19
  • 20 // constructor specifies default error message
  • 21 DivideByZeroException::DivideByZeroException()
  • 22 : exception( "attempted to divide by zero" ) {}
  • 23
  • 24 }; // end class DivideByZeroException
  • 25