prasadsunil
August 12th, 1999, 12:56 PM
I came across a problem with VC6 (w/ latest service packs) generating some bad code in exception handlers. In the following lines of code the two catch blocks get a return instruction generated, even though the logic should not return from the function here, and (even better) even though we are not in a returnable state - there is a stack frame and some registers saved on the stack (that get properly popped off when the function is supposed to return).
Won't work:
-------------------------------------------------------------------
//Some code...
//.
//.
//.
try
{
Exception Generating Code
}
catch(UserException* e) { e->Delete(); }
catch(...) {}
//More code...
//.
//.
//.
retun;
-------------------------------------------------------------------
Actually the UserException is derived from CException. When I look the Code in disassembly there are ret( return ) statements at the end of catch block. thus it is skipping the remaining code after the catch block. also stack rewinding.
Work around:
-------------------------------------------------------------------
//Some code...
//.
//.
//.
try
{
Exception generating code
}
catch(userException* e)
{ e->Delete(); __asm jmp Jmp1 }
catch(...) { __asm jmp Jmp1 }
Jmp1:
//More code...
//.
//.
//.
return;
-------------------------------------------------------------------
In the above block of code, the compiler still generates a return instruction after my jmp instruction, but the logic flow is correct now.
If anyone has any insight to this, please let me know.
----------------------
thanks
Won't work:
-------------------------------------------------------------------
//Some code...
//.
//.
//.
try
{
Exception Generating Code
}
catch(UserException* e) { e->Delete(); }
catch(...) {}
//More code...
//.
//.
//.
retun;
-------------------------------------------------------------------
Actually the UserException is derived from CException. When I look the Code in disassembly there are ret( return ) statements at the end of catch block. thus it is skipping the remaining code after the catch block. also stack rewinding.
Work around:
-------------------------------------------------------------------
//Some code...
//.
//.
//.
try
{
Exception generating code
}
catch(userException* e)
{ e->Delete(); __asm jmp Jmp1 }
catch(...) { __asm jmp Jmp1 }
Jmp1:
//More code...
//.
//.
//.
return;
-------------------------------------------------------------------
In the above block of code, the compiler still generates a return instruction after my jmp instruction, but the logic flow is correct now.
If anyone has any insight to this, please let me know.
----------------------
thanks