Windows core Programming Study Notes-Chapter 25

Source: Internet
Author: User

Chapter 2 unhandled exceptions, vectorized exceptions and C ++ exceptions

This chapter is purely for the sake of passing through the course.

1. Unprocessed exceptions:

1. How to filter exceptionsProgramReturns prediction_continue_search. The system continues to look for the exception filtering program on the upper layer of the call tree. If every exception filtering program returns prediction_continue_search, an unhandled exception occurs.

2. solution: the WINDOWS function setunhandledexceptionfilter gives us the last chance to handle the exception. Otherwise, Windows considers that the exception is not handled. This function should be called during process initialization.

Ptop_level_exception_filtersetunhandledexceptionfilter (

Ptop_level_exception_filterptoplevelexceptionfilter );

The exception filter function prototype must be similar to the following:

Long winapitoplevelunhandledexceptionfilter (pexception_pointers pexceptioninfo );

NOTE: If setunhandledexceptionfilter is called with null as the parameter, the unhandledexceptionfilter will be used to handle the global unhandled exception (before the process entry point function is executed when the C/C ++ Runtime library is used, the C/C ++ Runtime Library installs a default global exception filter program: _ cxxunhandledexceptionfilter. How does this function work: first, check whether the exception is a C ++ exception. If yes, execute the abort function at the end. The latter will call the unhandledexceptionfilter function in kernel32.dll. If no, prediction_continue_search is returned for Windows to handle this exception.

); If not, the automatic function is used to handle global unprocessed exceptions.

Ii. vectoring exception

She is based onCodeBox. Windows provides a vectorized exception handling mechanism. A program can register a function without relying on language-related keywords. This function is called whenever an exception occurs or an unprocessed exception is out of the standard she control.

Iii. Comparison of C ++ exceptions and structural exceptions

She is the convenience provided by the OS and can be used in any language. C ++ exception handling can only be used when writing C ++ code. If a C ++ program is developed, a C ++ exception is used. Because a C ++ exception is part of a language, the compiler knows what a C ++ object is, which means that the compiler automatically calls the generated code to call the destructor of the C ++ object, ensure the release of the object.

The Visual C ++ compiler uses structured OS exceptions to implement the C ++ exception handling mechanism. Comparison:

C ++

try

catch

throw

seh

__ try

__ invalid T

raiseexception

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.