OK, I put this in _tmain():
-
int result = ATest(5,0);
-
-
cout << "Result is: " << result << endl;
-
The ATest function looks like my cocd from my last reply except I have got it to compile and execute:
-
int ATest(int a, int b)
-
{
-
try
-
{
-
int* pb = &b;
-
*pb = MyFunction(a,b);
-
}
-
catch(CException* e)
-
{
-
cout << "Exception!!" << endl;
-
return 0;
-
}
-
return b;
-
}
-
-
-
-
int MyFunction(int first, int second)
-
{
-
if (second == 0) throw new CMemoryException;
-
-
return first/ second;
-
}
-
-
So, a call is made to ATest(). ATest trys MyFunction() passing in the two integers. If the second interge id 0, MyFunction() throws a MemoryException.
A CMemoryException IS-A CException. Therefore, it is caught using a CException pointer.
Try this code yourself with different values used in ther ATest() call in _tmain().