When exception is thrown in a function and not handled there, it is passed to calling function where it can be handled...exceptoin occurs in A() which shd get handled by catch block in main which doesnt happen ....Why?
Code:
#include <iostream>
using namespace std;
class A
{
int i;int j;
public:
A(int ii,int jj)
{
i=ii;
j=jj;
if(i<0)
throw exception(); // It should be passed in main function
}
};
int main()
{
A a1(-2,1);
try
{
}
catch(...) //It should actually catch the exception thrown by constructor
{ // but it doesn't happen...Pls clarify
cout<<"Exception caught in main";
}
}