Discuss how to handle exceptions on Windows

Source: Internet
Author: User

Originally published in QQ space:Exception Handling on Windows

A Brief Introduction to several types of exception handling on the Windows platform.

1. Uef (unhandledexceptionfilter): Use setunhandledexceptionfilter.CodeProcessing separately for the entire applicationProgramInstall a unified exception handling program and implement the Code in a simple and centralized manner. The disadvantage is that Windows is only responsible for maintaining a global function pointer. The subsequent setunhandledexceptionfilter call will overwrite the previous one. Many applications today use this function, this may prevent your code from being called. And it has the lowest priority. If veh or seh handles exceptions, UEF will have no idea. For more information, seeUnderstanding unhandledexceptionfilter

2. seh. In this way, each function can install its own exception processor with a higher priority than the unhandledexceptionfilter. Because seh is implemented by the compiler via stack handler, like call stack, seh is nested, And the seh of the inner function is called by the system before the seh of the outer layer. It looks pretty, but unfortunately you don't always want. For example, if you have multiple threads, even if all the exception handling processes are the same, you have to write the same code in each thread to implement Seh.

3. VEH, a bit similar to 1, provides a unified place to handle exceptions in the process. But the priority is higher than Seh. The disadvantage is that XP and later OS can use this function. In addition, Windows uses a linked list to record all registered veh. If the third-party code used in your code also calls VEH, you still cannot guarantee that your registered veh will be called. However, this disadvantage should be ignored because the above methods have similar problems. Since everyone has the same problem, it is okay.

When an exception occurs, Windows calls them in the order of 3, 2, and 1. What kind of exception handling is needed in your application?

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.