template<classT>T&Vector<T>::operator[](intindx){if(indx<0||indx>=m_size){// throw is a keyword// exception is raised at this pointthrow<<something>>;}returnm_elements[indx];}
classMathErr{...virtualvoiddiagnostic();};classOverflowErr:publicMathErr{...}classUnderflowErr:publicMathErr{...}classZeroDivideErr:publicMathErr{...}// Using handlerstry{// code to exercise math optionsthrowUnderFlowErr();}catch(ZeroDivideErr&e){// handle zero divide case}catch(MathErr&e){// handle other math errors}catch(...){// any other exceptions}
Printer::print(Document&):throw(PrinterOffLine,BadDocument){...PrintManager::print(Document&):throw(BadDocument){...// raises or doesn’t handle BadDocument voidgoodguy():throw(){// handles all exceptions voidaverage(){}// no spec, no checking,