I am running this program. As per my understanding, there should be a bad allocation exception raised within the try block and should cause a runtime failure. However, the program executes without any problem. I have the following questions:
Why is there no run-time error?
How does the control reach catch block even when no exceptions were thrown?
#include <iostream> using namespace std; int main() { int b =4, *c = NULL, i=-1; try{ c = new int [i]; b--; }catch (exception& e){ cout << "coming here" << endl; c = new int[1]; b++; } cout << b << endl; return 0; }