CS202 5- ‹#›
Catching Different Types of Exceptions
nint main() {
n  int i;
n  cout <<"Enter an integer: ";
n  cin >>i;
n
n  try {
n    if (i != 42) //detect error condition
n      throw i;   //throw an exception
n    cout <<"no throw was executed" <<endl;
n  }
n
n  catch(int x) { //catch integer exceptions
n    cout <<"exception handler called; arg = " <<x <<endl;
n    i = 42;      //set it to correct value
n  }
n
n  cout <<"normal program exit; i = " <<i <<endl;
n  return(0);
n}
n