You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Structured exception handling (SEH) is a Microsoft extension to C to handle certain exceptional code situations, such as hardware faults, gracefully. Although Windows and Microsoft C++ support SEH, we recommend that you use ISO-standard C++ exception handling. It makes your code more portable and flexible. However, to maintain existing code or for particular kinds of programs, you still might have to use SEH.
10
+
Structured exception handling (SEH) is a Microsoft extension to C and C++ to handle certain exceptional code situations, such as hardware faults, gracefully. Although Windows and Microsoft C++ support SEH, we recommend that you use ISO-standard C++ exception handling in C++ code. It makes your code more portable and flexible. However, to maintain existing code or for particular kinds of programs, you still might have to use SEH.
@@ -23,23 +23,23 @@ Structured exception handling (SEH) is a Microsoft extension to C to handle cert
23
23
24
24
With SEH, you can ensure that resources, such as memory blocks and files, get released correctly if execution unexpectedly terminates. You can also handle specific problems—for example, insufficient memory—by using concise structured code that doesn't rely on **`goto`** statements or elaborate testing of return codes.
25
25
26
-
The `try-except` and `try-finally` statements referred to in this article are Microsoft extensions to the C language. They support SEH by enabling applications to gain control of a program after events that would otherwise terminate execution. Although SEH works with C++ source files, it's not specifically designed for C++. If you use SEH in a C++ program that you compile by using the [`/EHa` or `/EHsc`](../build/reference/eh-exception-handling-model.md) option, destructors for local objects are called but other execution behavior might not be what you expect. For an illustration, see the example later in this article. In most cases, instead of SEH we recommend that you use ISO-standard [C++ exception handling](../cpp/try-throw-and-catch-statements-cpp.md), which the Microsoft C++ compiler also supports. By using C++ exception handling, you can ensure that your code is more portable, and you can handle exceptions of any type.
26
+
The [`try-except`](./try-except-statement.md) and [`try-finally`](./try-finally-statement.md) statements referred to in this article are Microsoft extensions to the C and C++ languages. They support SEH by enabling applications to gain control of a program after events that would otherwise terminate execution. Although SEH works with C++ source files, it's not specifically designed for C++. If you use SEH in a C++ program that you compile by using the [`/EHa` or `/EHsc`](../build/reference/eh-exception-handling-model.md) option, destructors for local objects are called, but other execution behavior might not be what you expect. For an illustration, see the example later in this article. In most cases, instead of SEH we recommend that you use ISO-standard [C++ exception handling](../cpp/try-throw-and-catch-statements-cpp.md). By using C++ exception handling, you can ensure that your code is more portable, and you can handle exceptions of any type.
27
27
28
28
If you have C code that uses SEH, you can mix it with C++ code that uses C++ exception handling. For information, see [Handle structured exceptions in C++](../cpp/exception-handling-differences.md).
29
29
30
30
There are two SEH mechanisms:
31
31
32
-
-[Exception handlers](../cpp/writing-an-exception-handler.md), or **`__except`** blocks, which can respond to or dismiss the exception.
32
+
-[Exception handlers](../cpp/writing-an-exception-handler.md), or **`__except`** blocks, which can respond to or dismiss the exception based on the *`filter-expression`* value. For more information, see [`try-except` statement](./try-except-statement.md).
33
33
34
-
-[Termination handlers](../cpp/writing-a-termination-handler.md), or **`__finally`** blocks, which are always called, whether an exception causes termination or not.
34
+
-[Termination handlers](../cpp/writing-a-termination-handler.md), or **`__finally`** blocks, which are always called, whether an exception causes termination or not. For more information, see [`try-finally` statement](./try-finally-statement.md).
35
35
36
36
These two kinds of handlers are distinct, but are closely related through a process known as *unwinding the stack*. When a structured exception occurs, Windows looks for the most recently installed exception handler that's currently active. The handler can do one of three things:
37
37
38
-
- Fail to recognize the exception and pass control to other handlers.
38
+
- Fail to recognize the exception and pass control to other handlers (`EXCEPTION_CONTINUE_SEARCH`).
39
39
40
-
- Recognize the exception but dismiss it.
40
+
- Recognize the exception but dismiss it (`EXCEPTION_CONTINUE_EXECUTION`).
41
41
42
-
- Recognize the exception and handle it.
42
+
- Recognize the exception and handle it (`EXCEPTION_EXECUTE_HANDLER`).
43
43
44
44
The exception handler that recognizes the exception may not be in the function that was running when the exception occurred. It may be in a function much higher on the stack. The currently running function and all other functions on the stack frame are terminated. During this process, the stack is *unwound*. That is, local non-static variables of terminated functions get cleared from the stack.
0 commit comments