#include using namespace std; // Multiple catches, both exceptions are handled properly. // Put more specific exceptions' catches first. // runtime_error is a kind of exception. If you want a separate // catch for each of them, the one for runtime_error must come first. int divide(int x, int y) { if (y == 0) throw 999; return x / y; } int main() { int * x; try { x = new int[1000000000]; x[0] = divide(7, 0); } catch (int e) { cout << "Failed because of reason #" << e << "\n"; } catch (exception e) { cout << "Failed because of " << e.what() << "\n"; } cout << "x = " << x << "\n"; delete [] x; }