try
{
delete m_CameraPtr;
}
catch (...)
{
// what does the ... represents? how to decode it?
// via va_list or something else?
}
🔒 Locked
🎮 Unity
[CPP] exception : catch all
Advertisement
Original Post
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 : its shame im still new to exception though i have played around with cpp for years. thanks for any responding, thank you.
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.
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.
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.
It will be helpful if you could show us how you created this pointer and what is the class it points to.
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,
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
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.
Quote:Oh, it gets worse.
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.
Much, much worse.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement