Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

[CPP] exception : catch all

Started by Pet123 7 replies 850+ views
Original Post
Pet123
Pet123
hello everyone my program will crash when i delete a (class) pointer, the class itself contains nothing special but some INTs and simple structs (like vector3). destructor of the class is executed , the crash point is where when the program leave the class's destructor. i dont know why it crashs here so i write a try-catch block to see if i can catch something usful, and i really caught something, but i dont know what the program wants to tell me, here is the code :


try
{ 
    delete m_CameraPtr;
}

catch (...)
{
   // what does the ... represents? how to decode it?
   // via va_list or something else?
}


its shame im still new to exception though i have played around with cpp for years. thanks for any responding, thank you.
Driv3MeFar
Driv3MeFar
The ellipses operator basically means "everything and anything", and in almost all cases should be avoided especially in catch blocks .

Maybe instead of using it to try to track down a crash you should just step though your code in a debugger and see what the value of your pointer is when you try to delete it, and why it is that value.
DesignerX
DesignerX
I use the (...) as the last catch for printing a message like "Unknown exception occured" just for not getting the ugly unhandled excepction crash. Although you MUST avoid exceptions that your other catch blocks can't identify.

It will be helpful if you could show us how you created this pointer and what is the class it points to.
There is nothing that can't be solved. Just people that can't solve it. :)
Nitage
Nitage
On Microsoft compilers, catch(...) will also catch system errors e.g. Access Violations.

The only way to retrieve the original exception is to throw; again and catch in the next matching try/catch block in the stack.
Emmanuel Deloget
Emmanuel Deloget
Quote:
Original post by Nitage
On Microsoft compilers, catch(...) will also catch system errors e.g. Access Violations.

To get this behavior in debug mode, you'll have to leave the handling of the acces violation exception to the program. By default, they are trapped by the debugger (I don't remember how to do it though; there must be a exception management windows somewhere...).

A better way to catch access violations (under Windows) is to use Structured Exception Handling. You'll get information such as the type of access violation, the address that was read or write, and so on.

Regards,
Anon Mike
Anon Mike
Quote:
Original post by Nitage
On Microsoft compilers, catch(...) will also catch system errors e.g. Access Violations.

That was true in VC6. It is not true (by default) in VC2005, I'm not sure about the one between those two. See the discussion about "asynchronous" vs "synchronous" exceptions in MSDN

For the OP, if delete is crashing that means your pointer is invalid, already freed, or you have corrupted the heap somehow. Trapping the crash is unlikely to give you any more information
-Mike
Excors
Excors
Testing suggests: VC2003 always catches non-C++ exceptions (e.g. access violations) in catch(...). VC2005 does so unless you use the /EHs flag (or the (deprecated) /GX) - that is probably the default in the IDE, and the command-line compiler suggests exception-using programs should use /EHsc (unless you've got /EHa instead, which I expect is unusual), so it's not quite the default behaviour (if you just run cl.exe) but it's pretty close.
Promit
Promit
Quote:
Original post by Excors
Testing suggests: VC2003 always catches non-C++ exceptions (e.g. access violations) in catch(...). VC2005 does so unless you use the /EHs flag (or the (deprecated) /GX) - that is probably the default in the IDE, and the command-line compiler suggests exception-using programs should use /EHsc (unless you've got /EHa instead, which I expect is unusual), so it's not quite the default behaviour (if you just run cl.exe) but it's pretty close.
Oh, it gets worse.

Much, much worse.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Nitage
Nitage
Well at least that explains why your catch block gets entered without you throwing any exceptions :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.