// From Teach Yourself C++, Second Edition by Herb Schildt // 11.3 Exception Handling p. 335-6 // Copyright Osborne Books, 1994 #include // Different types of exceptions can be caught. void Xhandler(int test) { char *zero = "Value is zero"; try { if(test) throw test; else throw zero; } catch (int i) { cout << "Caught One! Ex. #: "<< i << '\n'; } catch (char *str) { cout << "Caught a string: "; cout << str << '\n'; } } main() { cout << "start\n"; Xhandler(1); Xhandler(2); Xhandler(0); Xhandler(3); cout << "end\n"; return 0; } /* Program output: start Caught One! Ex. #: 1 Caught One! Ex. #: 2 Caught a string: Value is zero Caught One! Ex. #: 3 end */