Abnormal events

  • exceptions -- to indicate failure
  • intervention -- invocation of a correction routine

Exceptions in C++

\zline{\fbox{{\em try \& catch}}}
  class Matherr { }
  class Overflow : public Matherr {}
  
  try {
  	f(); 
do some arithmetic
} catch (Overflow) {
// handle Overflow
} catch (Matherr) {
// handle non-Overflow Matherr
}

Assertions

\zline{\fbox{{\em throw}}}
  template< class T, class X >
  inline void Assert(T expr, X x) {
     if (!NDEBUG) if (!expr) throw x;
     }
  

slide: Abnormal events