Skip to content

Commit cb77b07

Browse files
Merge pull request MicrosoftDocs#4546 from corob-msft/docs/corob/cpp-docs-4193
Update per cpp-docs 4193
2 parents 2498bcf + 7ba4129 commit cb77b07

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/cpp/structured-exception-handling-c-cpp.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
---
22
title: "Structured Exception Handling (C/C++)"
33
description: "An overview of structured exception handling in Microsoft C/C++."
4-
ms.date: 08/24/2020
4+
ms.date: 09/27/2022
55
helpviewer_keywords: ["termination handlers [C++], handling exceptions in C++", "structured exception handling [C++]", "try-catch keyword [C++], exception handlers", "C++ exception handling, termination handlers", "try-catch keyword [C++], termination handlers", "C++ exception handling, exception handlers"]
66
ms.assetid: dd3b647d-c269-43a8-aab9-ad1458712976
77
---
88
# Structured Exception Handling (C/C++)
99

10-
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.
1111

1212
**Microsoft-specific:**
1313

1414
## Grammar
1515

1616
> *`try-except-statement`* :<br/>
17-
> &emsp;**`__try`** *`compound-statement`* **`__except`** **`(`** *`expression`* **`)`** *`compound-statement`*
17+
> &emsp;**`__try`** *`compound-statement`* **`__except`** **`(`** *`filter-expression`* **`)`** *`compound-statement`*
1818
>
1919
> *`try-finally-statement`* :<br/>
2020
> &emsp;**`__try`** *`compound-statement`* **`__finally`** *`compound-statement`*
@@ -23,23 +23,23 @@ Structured exception handling (SEH) is a Microsoft extension to C to handle cert
2323

2424
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.
2525

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.
2727

2828
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).
2929

3030
There are two SEH mechanisms:
3131

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).
3333

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).
3535

3636
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:
3737

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`).
3939

40-
- Recognize the exception but dismiss it.
40+
- Recognize the exception but dismiss it (`EXCEPTION_CONTINUE_EXECUTION`).
4141

42-
- Recognize the exception and handle it.
42+
- Recognize the exception and handle it (`EXCEPTION_EXECUTE_HANDLER`).
4343

4444
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.
4545

0 commit comments

Comments
 (0)