try{ // do something with // potential thrown // exception. } catch( exception ){ // handle the error }
double divide(double a, double b) { if(b==0) throw("Cannot divide by zero\n"); return(a/b); } ... try{ cout << divide(4,0); } catch(const char* err) { cout << err << endl; }