In the following code I want to catch either asynchronous and synchronous exceptions by use of c++ catch (...) according Microsoft Page descriptions about Exception Handling Model.
Also I set the "Exception Handling Model" up to Yes with SEH Exceptions (/EHa)
value.
I tested the code with the following states respectively :
When I copy a string in an unallocated
char*
(char *c;
), then i can catch its exception incatch (...)
section. (However I know this is an undefined behavior!)But when I copy a string in an array of characters (the string is larger than the array size), then I can't catch any exception !!
In the 2nd state, while debugging I got Access Violation error. but why cannot catch its exception like the 1st state ??
I tried another solutions as mentioned in :
But also The problem persists.
This is my code (I tested strcpy()
either on an unallocated char*
and on an array of characters):
int main()
{
char c[3] = { 0 }; // Cannot catch any exception
//char *c; // Can catch exception
try
{
strcpy(c, "abcdefghijklmnopqrstuvwxyz1234567890");
}
catch (...)
{
cout << "Undefined behavior!" << endl;
}
return 0;
}