Re: compile error about destructor
On Feb 20, 6:33 pm, George <Geo...@discussions.microsoft.com> wrote:
Hi Ben,
I have tried your code, and your code will cause application deadlock
symptom (after statement throw)? Hand-up? Here is the whole code,
The problem is with your incorrect usage of SEH as below:
int main()
{
__try{
helper();} __except (GetExceptionCode())
{
cout << "access violation caught 2" << endl;
}
return 0;
}
The __except handler is incorrect. There are only 3 valid values for
it. If the result of the expression for __except is anything other
than those 3 values probably it gets blocked searching for an
appropriate value (or whatever as per msdn, I am not sure what blocks
the execution) and hence the execution hangs up. You should rephrase
that as below:
__try
{
helper();
}
__except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ?
EXCEPTION_EXECUTE_HANDLER :
EXCEPTION_CONTINUE_EXECUTION)
{
cout << "access violation caught 2" << endl;
}
Note the use of "__finally" in Ben's response.