Try {} catch (...){}
In the past, try {} catch (...) was used (...) {} to catch some unexpected exceptions in C ++. Today, I read winhack's post and I realized that this method is actually used in VC.
It is unreliable. For example, the following code;
Try <br/> {<br/> byte * PCH; <br/> PCH = (byte *) 00001234; // give an invalid address <br/> * PCH = 6; // assign a value to the Invalid Address, access violation exception <br/>}< br/> catch (...) <br/>{< br/> afxmessagebox ("catched"); <br/>}
There is no problem with this code in debug. Exceptions will be caught and a message box of "catched" will pop up. However, if the compiler code is selected in the release mode
Optimization Options, the VC compiler will search for the code in the try block. If the throw code is not found, the VC compiler will think that the try catch structure is redundant and optimized.
In release mode, exceptions in the above Code cannot be captured, and the program is forced to exit with an error prompt box.
So can we catch this exception in the release code optimization status? The answer is yes. Is the structure of _ Try, _ struct T. If the above Code is changed to the following code:
Exception can be captured
_ Try <br/>{< br/> byte * PCH; <br/> PCH = (byte *) 00001234; // give an invalid address </P> <p> * PCH = 6; // assign a value to the Invalid Address, access violation exception may occur <br/>}< br/>__ except T (exception_execute_handler) <br/>{< br/> afxmessagebox ("catched "); <br/>}< br/>
But there is still a problem when using the _ Try, __except block, that is, this is not a C ++ standard, but a Windows platform-specific extension. In addition
When you design a local object destructor call, a c2712 compilation error occurs. Is there any other way?
Of course, it is still using the C ++ standard try {} catch (...) {}, but adding the/EHA parameter to the compile command line. In this way, the VC compiler will not take the try and catch modules
Optimized
From: http://www.doyj.com/2006/09/11/try-catch/