Ide:vc6
Today encountered a small problem, put me depressed for a long time, XX doctor's vulengine occasionally in Wcsstr place crash, add a powerful parameter check, plus a strong try catch, actually not very like with try and catch, always feel a perfect program, Should be the code of every place can be controlled by the programmer, I tend to like the function of the return value and parameters of the mandatory check, of course, this requires you to design the function must also meet these requirements, but things involved in reading and writing files, processing strings and so cumbersome operations, occasionally with a try catch is relatively concise , I add exception handling code after WCSSTR, debug under very perfect, an exception (null pointer, string unreadable), is captured, the program is no longer crash, but the release will still appear crash problem, what,happend?
Later to check the information to know, under release, if there is no throw statement in the TRY statement block (including the called function), then the entire try catch is optimized by the compiler, but this is in accordance with the C + + standard, because the C + + standard says, Catch must be able to catch all exceptions thrown through the throw statement in the program, as for the memory access violation, by 0, and so on system exceptions, the C + + standard does not require, but VC extension _try _catch seems to be possible, relatively strong. Now, it's a cup of tea, I didn't know how many try catch I've written before, but I never really paid attention to this question, and I don't know if it was optimized to expose your fragile code to a fussy windows like nudity.
It is not difficult to solve the above problem, but adding/EHa to the compilation option prevents the compiler from optimizing the Try statement.
In general, C + + exception handling is still relatively dependent on different compilers and systems, not very stable, transplant is also poor, Java exception handling and always feel not the pan, let people have no choice, but rather like the exception of Python processing mechanism, hey.
The powerful reason for exception handling under the Windows platform is the system's SEH (structured exception) processing mechanism, in fact, the try catch is also implemented using SEH's variant encapsulation. Recently is looking at this information, a bit of experience to write again.
[CPP]View PlainCopy
- Try
- {
- wchar_t* pch;
- PCH = (wchar_t*) 0x10001022;
- Wcsstr (PCH, L"abc");
- }
- catch (...)
- {
- printf ("catched a exception/n");
- }
http://blog.csdn.net/magictong/article/details/5504735
VC6 the cup with the try catch under release (by default, the catch will not be optimized by adding a throw statement)