#include #include using namespace std; class NegativeNumber { public: NegativeNumber() {}; NegativeNumber(string theMessage) : message(theMessage) {}; string getMessage() const {return message;} private: string message; }; class DivideByZero {}; main() { int i; for (i=0; i<10; i++) { try { if (i % 4 == 0) throw NegativeNumber("A negative number error"); else if (i % 2 == 0) throw DivideByZero(); else throw 0.5; } catch (NegativeNumber e) { cout << "get NegativeNumber exception no: " << e.getMessage() << endl; } catch (DivideByZero) { cout << "get DivideByZero exception\n"; } catch(...) { cout << "get other exception\n"; } } }