VC6 the cup with the try catch under release (by default, the catch will not be optimized by adding a throw statement)

Source: Internet
Author: User

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
    1. Try
    2. {
    3. wchar_t* pch;
    4. PCH = (wchar_t*) 0x10001022;
    5. Wcsstr (PCH, L"abc");
    6. }
    7. catch (...)
    8. {
    9. printf ("catched a exception/n");
    10. }

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.