Skip to content

Commit 2472d45

Browse files
authored
Merge pull request #2350 from corob-msft/cr-1574
Fix __except keyword per 1574
2 parents 2faade9 + 58c5065 commit 2472d45

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

docs/cpp/exception-handling-differences.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: "Handle structured exceptions in C++"
3-
ms.date: "08/14/2018"
3+
description: How to handle structured exceptions using the C++ exception handling model.
4+
ms.date: "09/19/2019"
45
helpviewer_keywords: ["structured exception handling [C++], vs. C++ exception handling", "structured exception handling [C++], vs. unstructured", "exceptions [C++], wrapper class", "C++ exception handling [C++], vs. structured exception handling", "wrapper classes [C++], C exception"]
56
ms.assetid: f21d1944-4810-468e-b02a-9f77da4138c9
67
---
@@ -10,9 +11,9 @@ The major difference between C structured exception handling (SEH) and C++ excep
1011

1112
A second difference is that the C structured exception handling model is referred to as *asynchronous*, because exceptions occur secondary to the normal flow of control. The C++ exception handling mechanism is fully *synchronous*, which means that exceptions occur only when they are thrown.
1213

13-
When you use the [/EHs or /EHsc](../build/reference/eh-exception-handling-model.md) compiler option, no C++ exception handlers handle structured exceptions. These exceptions are handled only by **__catch** structured exception handlers or **__finally** structured termination handlers. For information, see [Structured Exception Handling (C/C++)](structured-exception-handling-c-cpp.md).
14+
When you use the [/EHs or /EHsc](../build/reference/eh-exception-handling-model.md) compiler option, no C++ exception handlers handle structured exceptions. These exceptions are handled only by **__except** structured exception handlers or **__finally** structured termination handlers. For information, see [Structured Exception Handling (C/C++)](structured-exception-handling-c-cpp.md).
1415

15-
Under the [/EHa](../build/reference/eh-exception-handling-model.md) compiler option, if a C exception is raised in a C++ program, it can be handled by a structured exception handler with its associated filter or by a C++ **catch** handler, whichever is dynamically nearer to the exception context. For example, the following C++ program raises a C exception inside a C++ **try** context:
16+
Under the [/EHa](../build/reference/eh-exception-handling-model.md) compiler option, if a C exception is raised in a C++ program, it can be handled by a structured exception handler with its associated filter or by a C++ **catch** handler, whichever is dynamically nearer to the exception context. For example, this sample C++ program raises a C exception inside a C++ **try** context:
1617

1718
## Example - Catch a C exception in a C++ catch block
1819

@@ -51,7 +52,7 @@ Caught a C exception.
5152

5253
## C exception wrapper classes
5354

54-
In a simple example like the above, the C exception can be caught only by an ellipsis (**...**) **catch** handler. No information about the type or nature of the exception is communicated to the handler. While this method works, in some cases you may want to define a transformation between the two exception handling models so that each C exception is associated with a specific class. To do this, you can define a C exception "wrapper" class, which can be used or derived from in order to attribute a specific class type to a C exception. By doing so, each C exception can be handled separately by a specific C++ **catch** handler, instead of all of them in a single handler.
55+
In a simple example like the above, the C exception can be caught only by an ellipsis (**...**) **catch** handler. No information about the type or nature of the exception is communicated to the handler. While this method works, in some cases you may want to define a transformation between the two exception handling models so that each C exception is associated with a specific class. To transform one, you can define a C exception "wrapper" class, which can be used or derived from in order to attribute a specific class type to a C exception. By doing so, each C exception can be handled separately by a specific C++ **catch** handler, instead of all of them in a single handler.
5556

5657
Your wrapper class might have an interface consisting of some member functions that determine the value of the exception, and that access the extended exception context information provided by the C exception model. You might also want to define a default constructor and a constructor that accepts an **unsigned int** argument (to provide for the underlying C exception representation), and a bitwise copy constructor. Here is a possible implementation of a C exception wrapper class:
5758

@@ -72,7 +73,7 @@ public:
7273
};
7374
```
7475
75-
To use this class, install a custom C exception translation function that is called by the internal exception handling mechanism each time a C exception is thrown. Within your translation function, you can throw any typed exception (perhaps an `SE_Exception` type, or a class type derived from `SE_Exception`) that can be caught by an appropriate matching C++ **catch** handler. The translation function can simply return, which indicates that it did not handle the exception. If the translation function itself raises a C exception, [terminate](../c-runtime-library/reference/terminate-crt.md) is called.
76+
To use this class, install a custom C exception translation function that is called by the internal exception handling mechanism each time a C exception is thrown. Within your translation function, you can throw any typed exception (perhaps an `SE_Exception` type, or a class type derived from `SE_Exception`) that can be caught by an appropriate matching C++ **catch** handler. The translation function can instead return, which indicates that it did not handle the exception. If the translation function itself raises a C exception, [terminate](../c-runtime-library/reference/terminate-crt.md) is called.
7677
7778
To specify a custom translation function, call the [_set_se_translator](../c-runtime-library/reference/set-se-translator.md) function with the name of your translation function as its single argument. The translation function that you write is called once for each function invocation on the stack that has **try** blocks. There is no default translation function; if you do not specify one by calling **_set_se_translator**, the C exception can only be caught by an ellipsis **catch** handler.
7879

0 commit comments

Comments
 (0)