Jump to content
  • Advertisement
Sign in to follow this  
Kitt3n

Crash after throwing exception

This topic is 4827 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!