Windows kernel reading notes--seh structured exception handling

Source: Internet
Author: User

SEH is the generic name for the exception distribution and processing mechanism in Windows systems, and its implementation is distributed in many different modules.

SEH provides two functions for terminating processing and exception handling .

Finalization processing guarantees that the program in the end processing block must be executed

1 __try 2 {3// code 4} to protect 5 __finally 6 {7// End processing block 8 }

How to exit the protection block: normal end and abnormal end two types of

1. Normal End

Normal execution and sequential entry to the end processing block is called normal end

2. Non-normal end

Because of an exception or because of a process control statement such as return, Goto, break, continue, and so on, leaving the protected block is called an abnormal end.

Use abnormaltermination in the finalization processing block to obtain the exit mode of the protected block.

The __leave keyword is used in the protected block and immediately ends the protected block. belongs to normal exit.

Exception handling features for handling exceptions

1 __try 2 {3// protected block 4} 5 __except (filter expression) 6 {7// exception handling block 8 }

Provides two macros that can be used within a filter expression or exception-handling block

GetExceptionCode () returns the exception code

GetExceptionInformation () returns a exception_pointers structure

1 struct _exception_pointers {2  pexception_record exceptionrecord;//exception record pointer 3   PCONTEXT          contextrecord;//thread Context pointer 4 } exception_pointers, *pexception_pointers;

A filter expression can be a constant, or a function call can be a conditional expression, but the last value must be one of 1, 0, 1.

Exception_continue_search (0) This protection block does not handle exceptions, the system continues to search other protection blocks

Exception_continue_execution (1) has handled the exception, the program goes back to the anomaly and continues to run.

Exception_execute_handle (-1) Allow this protection block to handle this

Windows kernel reading notes--seh structured exception handling

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.