Crash after throwing exception

Started by
1 comment, last by Kitt3n 18 years, 7 months ago
Hi, I'm throwing an exception and then I land in my exception-handler (which is currently a try/catch block inside my WinMain(). Here I log the error to a file - and at the closing } it crashes with the following callstack. I'm not really sure where to find the problem or what might be wrong. any suggestions would be welcome __DestructExeptionObject(EHExeptionRecord* pExept, ...) <= CRASH CallCatchBlock(EHExeptionRecord* pExept, ...) CallCatchBlock(EHExeptionRecord* pExept, ...) CatchIt(EHExeptionRecord* pExept, ...) FindHandler (EHExeptionRecord* pExept, ...) __InternalCxxFrameHandler (EHExeptionRecord* pExept, ...) __CxxFrameHandler (EHExeptionRecord* pExept, ...) NTDLL (4 times) Kernel32.dll Kernel32.dll My Catch-block looks like this:

{
  try
  { // mainloop 
  } 
  catch( MyNameSpace::Exception& e ) 
  { // Output to file
  } <= Here it crashes
  catch (std::exception& e)
  {
  }
}
Thanks
visit my website at www.kalmiya.com
Advertisement
Quote:Original post by Kitt3n
Hi,

I'm throwing an exception and then I land in my exception-handler (which
is currently a try/catch block inside my WinMain().
Here I log the error to a file - and at the closing } it crashes with
the following callstack.
I'm not really sure where to find the problem or what might be wrong.
any suggestions would be welcome


__DestructExeptionObject(EHExeptionRecord* pExept, ...) <= CRASH
CallCatchBlock(EHExeptionRecord* pExept, ...)
CallCatchBlock(EHExeptionRecord* pExept, ...)
CatchIt(EHExeptionRecord* pExept, ...)
FindHandler (EHExeptionRecord* pExept, ...)
__InternalCxxFrameHandler (EHExeptionRecord* pExept, ...)
__CxxFrameHandler (EHExeptionRecord* pExept, ...)
NTDLL (4 times)
Kernel32.dll
Kernel32.dll

My Catch-block looks like this:
{  try  { // mainloop   }   catch( MyNameSpace::Exception& e )   { // Output to file  } <= Here it crashes  catch (std::exception& e)  {  }}


Thanks

Propabbly some class that is being destructed in the catch scope cause you this error.
In debug mode.
Try to put some dummy line isnide the catch, break at that line.
Then try to enter the destructor you know should be called when the catch scope ends, and see what happens in it. Then jump to the destructor that should be called next (still by the end of the catch scope) and so on until you find the problem.

It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Okay, I found it - indeed it had to do with a destructor being called,
but not one inside the catch-block, but rather inside the try block!
A little more code to illustrate the problem (and help anyone else
who might have a simular problem :)

  try  {     MyMainApp theApp; // theApp loads a DLL    // the DLL will throw an exception-object (little wrapper    // class which has a string with a description)          }   catch( MyNameSpace::Exception& e )   {     // Try-block goes out of scope, the theApp is destroyed,    // and with it the DLL which threw the exception.    // Output to file  } <= Here it crashes => ExceptionHandlers tries to destroy the                   exceptionobject, but since the DLL is gone that crashes  catch (std::exception& e)  {  }


I fixed it by moving the MyMainApp outside the try-block and
making a pointer of it. The new MyMainApp will remain inside
the try (so exceptions are caught). The pointer is then destroyed
after the catch-blocks.

Thanks!
visit my website at www.kalmiya.com

This topic is closed to new replies.

Advertisement