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 |