Skip to content
3 changes: 2 additions & 1 deletion docs/build/exception-handling-x64.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "x64 exception handling"
description: "Overview of Microsoft C++ exception handling conventions on x64."
ms.date: "10/14/2019"
helpviewer_keywords: ["C++ exception handling, x64", "exception handling, x64"]
ms.assetid: 41fecd2d-3717-4643-b21c-65dcd2f18c93
Expand Down Expand Up @@ -297,7 +298,7 @@ typedef struct _DISPATCHER_CONTEXT {
} DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
```

**ControlPc** is the value of RIP within this function. This value is either an exception address or the address at which control left the establishing function. The RIP is used to determine if control is within some guarded construct inside this function, for example, a `__try` block for `__try`/**`__except`** or `__try`/**`__finally`**.
**ControlPc** is the value of RIP within this function. This value is either an exception address or the address at which control left the establishing function. The RIP is used to determine if control is within some guarded construct inside this function, for example, a **`__try`** block for **`__try`**/**`__except`** or **`__try`**/**`__finally`**.

**ImageBase** is the image base (load address) of the module containing this function, to be added to the 32-bit offsets used in the function entry and unwind info to record relative addresses.

Expand Down
22 changes: 11 additions & 11 deletions docs/build/reference/eh-exception-handling-model.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
title: "/EH (Exception handling model)"
description: "Reference guide to the Microsoft C++ /EH (Exception handling model) compiler options in Visual Studio."
ms.date: "04/14/2020"
ms.date: 08/25/2020
f1_keywords: ["VC.Project.VCCLWCECompilerTool.ExceptionHandling", "/eh", "VC.Project.VCCLCompilerTool.ExceptionHandling"]
helpviewer_keywords: ["exception handling, compiler model", "cl.exe compiler, exception handling", "EH compiler option [C++]", "-EH compiler option [C++]", "/EH compiler option [C++]"]
no-loc: [SEH, try, catch, throw, extern, finally, noexcept]
ms.assetid: 754b916f-d206-4472-b55a-b6f1b0f2cb4d
---
# /EH (Exception handling model)
# `/EH` (Exception handling model)

Specifies the exception handling model support generated by the compiler. Arguments specify whether to apply `catch(...)` syntax to both structured and standard C++ exceptions, whether **extern "C"** code is assumed to throw exceptions, and whether to optimize away certain **`noexcept`** checks.

Expand Down Expand Up @@ -41,7 +41,7 @@ Clears the previous option argument. For example, **`/EHsc-`** is interpreted as

### Default exception handling behavior

The compiler always generates code that supports asynchronous structured exception handling (SEH). By default (that is, if no **`/EHsc`**, **`/EHs`**, or **`/EHa`** option is specified), the compiler supports SEH handlers in the native C++ `catch(...)` clause. However, it also generates code that only partially supports C++ exceptions. The default exception unwinding code doesn't destroy automatic C++ objects outside of [try](../../cpp/try-throw-and-catch-statements-cpp.md) blocks that go out of scope because of an exception. Resource leaks and undefined behavior may result when a C++ exception is thrown.
The compiler always generates code that supports asynchronous structured exception handling (SEH). By default (that is, if no **`/EHsc`**, **`/EHs`**, or **`/EHa`** option is specified), the compiler supports SEH handlers in the native C++ `catch(...)` clause. However, it also generates code that only partially supports C++ exceptions. The default exception unwinding code doesn't destroy automatic C++ objects outside of [`try`](../../cpp/try-throw-and-catch-statements-cpp.md) blocks that go out of scope because of an exception. Resource leaks and undefined behavior may result when a C++ exception is thrown.

### Standard C++ exception handling

Expand All @@ -53,12 +53,12 @@ When you use **`/EHs`** or **`/EHsc`**, the compiler assumes that exceptions can

### Structured and standard C++ exception handling

The **`/EHa`** compiler option enables safe stack unwinding for both asynchronous exceptions and C++ exceptions. It supports handling of both standard C++ and structured exceptions by using the native C++ `catch(...)` clause. To implement SEH without specifying **`/EHa`**, you may use the **__try**, **`__except`**, and **`__finally`** syntax. For more information, see [Structured exception handling](../../cpp/structured-exception-handling-c-cpp.md).
The **`/EHa`** compiler option enables safe stack unwinding for both asynchronous exceptions and C++ exceptions. It supports handling of both standard C++ and structured exceptions by using the native C++ `catch(...)` clause. To implement SEH without specifying **`/EHa`**, you may use the **`__try`**, **`__except`**, and **`__finally`** syntax. For more information, see [Structured exception handling](../../cpp/structured-exception-handling-c-cpp.md).

> [!IMPORTANT]
> Specifying **`/EHa`** and trying to handle all exceptions by using `catch(...)` can be dangerous. In most cases, asynchronous exceptions are unrecoverable and should be considered fatal. Catching them and proceeding can cause process corruption and lead to bugs that are hard to find and fix.
>
> Even though Windows and Visual C++ support SEH, we strongly recommend that you use ISO-standard C++ exception handling (**`/EHsc`** or **`/EHs`**). It makes your code more portable and flexible. There may still be times you have to use SEH in legacy code or for particular kinds of programs. It's required in code compiled to support the common language runtime ([/clr](clr-common-language-runtime-compilation.md)), for example. For more information, see [Structured exception handling](../../cpp/structured-exception-handling-c-cpp.md).
> Even though Windows and Visual C++ support SEH, we strongly recommend that you use ISO-standard C++ exception handling (**`/EHsc`** or **`/EHs`**). It makes your code more portable and flexible. There may still be times you have to use SEH in legacy code or for particular kinds of programs. It's required in code compiled to support the common language runtime ([`/clr`](clr-common-language-runtime-compilation.md)), for example. For more information, see [Structured exception handling](../../cpp/structured-exception-handling-c-cpp.md).
>
> We recommend that you never link object files compiled using **`/EHa`** to ones compiled using **`/EHs`** or **`/EHsc`** in the same executable module. If you have to handle an asynchronous exception by using **`/EHa`** anywhere in your module, use **`/EHa`** to compile all the code in the module. You can use structured exception handling syntax in the same module as code that's compiled by using **`/EHs`**. However, you can't mix the SEH syntax with C++ **`try`**, **`throw`**, and **`catch`** in the same function.

Expand Down Expand Up @@ -111,9 +111,9 @@ For information about exception handling restrictions under **`/clr`**, see [_se

### Runtime exception checks

The **`/EHr`** option forces runtime termination checks in all functions that have a **`noexcept`** attribute. By default, runtime checks may be optimized away if the compiler back-end determines that a function only calls *non-throwing* functions. Non-throwing functions are any functions that have an attribute that specifies no exceptions may be thrown. They include functions marked **`noexcept`**, `throw()`, `__declspec(nothrow)`, and, when **`/EHc`** is specified, **extern "C"** functions. Non-throwing functions also include any that the compiler has determined are non-throwing by inspection. You can explicitly set the default behavior by using **`/EHr-`**.
The **`/EHr`** option forces runtime termination checks in all functions that have a **`noexcept`** attribute. By default, runtime checks may be optimized away if the compiler back-end determines that a function only calls *non-throwing* functions. Non-throwing functions are any functions that have an attribute that specifies no exceptions may be thrown. They include functions marked **`noexcept`**, `throw()`, `__declspec(nothrow)`, and, when **`/EHc`** is specified, **`extern "C"`** functions. Non-throwing functions also include any that the compiler has determined are non-throwing by inspection. You can explicitly set the default behavior by using **`/EHr-`**.

A non-throwing attribute isn't a guarantee that exceptions can't be thrown by a function. Unlike the behavior of a **`noexcept`** function, the MSVC compiler considers an exception thrown by a function declared using `throw()`, `__declspec(nothrow)`, or **extern "C"** as undefined behavior. Functions that use these three declaration attributes don't enforce runtime termination checks for exceptions. You can use the **`/EHr`** option to help you identify this undefined behavior, by forcing the compiler to generate runtime checks for unhandled exceptions that escape a **`noexcept`** function.
A non-throwing attribute isn't a guarantee that exceptions can't be thrown by a function. Unlike the behavior of a **`noexcept`** function, the MSVC compiler considers an exception thrown by a function declared using `throw()`, `__declspec(nothrow)`, or **`extern "C"`** as undefined behavior. Functions that use these three declaration attributes don't enforce runtime termination checks for exceptions. You can use the **`/EHr`** option to help you identify this undefined behavior, by forcing the compiler to generate runtime checks for unhandled exceptions that escape a **`noexcept`** function.

## Set the option in Visual Studio or programmatically

Expand All @@ -133,8 +133,8 @@ A non-throwing attribute isn't a guarantee that exceptions can't be thrown by a

## See also

[MSVC Compiler Options](compiler-options.md)\
[MSVC Compiler Command-Line Syntax](compiler-command-line-syntax.md)\
[Errors and Exception Handling](../../cpp/errors-and-exception-handling-modern-cpp.md)\
[Exception Specifications (throw)](../../cpp/exception-specifications-throw-cpp.md)\
[MSVC Compiler options](compiler-options.md)\
[MSVC Compiler command-line syntax](compiler-command-line-syntax.md)\
[Errors and exception handling](../../cpp/errors-and-exception-handling-modern-cpp.md)\
[Exception specifications (throw)](../../cpp/exception-specifications-throw-cpp.md)\
[Structured Exception Handling (C/C++)](../../cpp/structured-exception-handling-c-cpp.md)
114 changes: 59 additions & 55 deletions docs/c-language/summary-of-statements.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,65 @@
---
title: "Summary of Statements"
ms.date: "11/04/2016"
title: "Summary of C statements"
description: "A summary of the statement grammar in the Microsoft C implementation."
ms.date: 08/24/2020
ms.assetid: ce45d2fe-ec0e-459f-afb1-80ab6a7f0239
---
# Summary of Statements

*statement*:<br/>
&nbsp;&nbsp;&nbsp;&nbsp;*labeled-statement*<br/>
&nbsp;&nbsp;&nbsp;&nbsp;*compound-statement*<br/>
&nbsp;&nbsp;&nbsp;&nbsp;*expression-statement*<br/>
&nbsp;&nbsp;&nbsp;&nbsp;*selection-statement*<br/>
&nbsp;&nbsp;&nbsp;&nbsp;*iteration-statement*<br/>
&nbsp;&nbsp;&nbsp;&nbsp;*jump-statement*<br/>
&nbsp;&nbsp;&nbsp;&nbsp;*try-except-statement* /\* Microsoft-specific \*/<br/>
&nbsp;&nbsp;&nbsp;&nbsp;*try-finally-statement* /\* Microsoft-specific \*/

*jump-statement*:<br/>
&nbsp;&nbsp;&nbsp;&nbsp;**`goto`** *identifier* **;**<br/>
&nbsp;&nbsp;&nbsp;&nbsp;**continue ;**<br/>
&nbsp;&nbsp;&nbsp;&nbsp;**break ;**<br/>
&nbsp;&nbsp;&nbsp;&nbsp;**`return`** *expression*<sub>opt</sub> **;**

*compound-statement*:<br/>
&nbsp;&nbsp;&nbsp;&nbsp;**{** *declaration-list*<sub>opt</sub> *statement-list*<sub>opt</sub> **}**

*declaration-list*:<br/>
&nbsp;&nbsp;&nbsp;&nbsp;*declaration*<br/>
&nbsp;&nbsp;&nbsp;&nbsp;*declaration-list* *declaration*

*statement-list*:<br/>
&nbsp;&nbsp;&nbsp;&nbsp;*statement*<br/>
&nbsp;&nbsp;&nbsp;&nbsp;*statement-list* *statement*

*expression-statement*:<br/>
&nbsp;&nbsp;&nbsp;&nbsp;*expression*<sub>opt</sub> **;**

*iteration-statement*:<br/>
&nbsp;&nbsp;&nbsp;&nbsp;**while (** *expression* **)** *statement*<br/>
&nbsp;&nbsp;&nbsp;&nbsp;**`do`** *statement* **while (** *expression* **) ;**<br/>
&nbsp;&nbsp;&nbsp;&nbsp;**for (** *expression*<sub>opt</sub> **;** *expression*<sub>opt</sub> **;** *expression*<sub>opt</sub> **)** *statement*

*selection-statement*:<br/>
&nbsp;&nbsp;&nbsp;&nbsp;**if (** *expression* **)** *statement*<br/>
&nbsp;&nbsp;&nbsp;&nbsp;**if (** *expression* **)** *statement* **`else`** *statement*<br/>
&nbsp;&nbsp;&nbsp;&nbsp;**switch (** *expression* **)** *statement*

*labeled-statement*:<br/>
&nbsp;&nbsp;&nbsp;&nbsp;*identifier* **:** *statement*<br/>
&nbsp;&nbsp;&nbsp;&nbsp;**`case`** *constant-expression* **:** *statement*<br/>
&nbsp;&nbsp;&nbsp;&nbsp;**default :** *statement*

*try-except-statement*: /\* Microsoft-specific \*/<br/>
&nbsp;&nbsp;&nbsp;&nbsp;**__try** *compound-statement* **__except (** *expression* **)** *compound-statement*

*try-finally-statement*: /\* Microsoft-specific \*/<br/>
&nbsp;&nbsp;&nbsp;&nbsp;**__try** *compound-statement* **`__finally`** *compound-statement*
# Summary of C statements

*`statement`*:<br/>
&emsp;*`labeled-statement`*<br/>
&emsp;*`compound-statement`*<br/>
&emsp;*`expression-statement`*<br/>
&emsp;*`selection-statement`*<br/>
&emsp;*`iteration-statement`*<br/>
&emsp;*`jump-statement`*<br/>
&emsp;*`try-except-statement`* /\* Microsoft-specific \*/<br/>
&emsp;*`try-finally-statement`* /\* Microsoft-specific \*/

*`jump-statement`*:<br/>
&emsp;**`goto`** *`identifier`* **`;`**<br/>
&emsp;**`continue ;`**<br/>
&emsp;**`break ;`**<br/>
&emsp;**`return`** *`expression`*<sub>opt</sub> **`;`**<br/>
&emsp;**`__leave ;`** /\* Microsoft-specific<sup>1</sup> \*/

*`compound-statement`*:<br/>
&emsp;**`{`** *`declaration-list`*<sub>opt</sub> *`statement-list`*<sub>opt</sub> **`}`**

*`declaration-list`*:<br/>
&emsp;*`declaration`*<br/>
&emsp;*`declaration-list`* *`declaration`*

*`statement-list`*:<br/>
&emsp;*`statement`*<br/>
&emsp;*`statement-list`* *`statement`*

*`expression-statement`*:<br/>
&emsp;*`expression`*<sub>opt</sub> **`;`**

*`iteration-statement`*:<br/>
&emsp;**`while (`** *`expression`* **`)`** *`statement`*<br/>
&emsp;**`do`** *`statement`* **`while (`** *`expression`* **`) ;`**<br/>
&emsp;**`for (`** *`expression`*<sub>opt</sub> **`;`** *`expression`*<sub>opt</sub> **`;`** *`expression`*<sub>opt</sub> **`)`** *`statement`*

*`selection-statement`*:<br/>
&emsp;**`if (`** *`expression`* **`)`** *`statement`*<br/>
&emsp;**`if (`** *`expression`* **`)`** *`statement`* **`else`** *`statement`*<br/>
&emsp;**`switch (`** *`expression`* **`)`** *`statement`*

*`labeled-statement`*:<br/>
&emsp;*`identifier`* **`:`** *`statement`*<br/>
&emsp;**`case`** *`constant-expression`* **`:`** *`statement`*<br/>
&emsp;**`default :`** *`statement`*

*`try-except-statement`*: /\* Microsoft-specific \*/<br/>
&emsp;**`__try`** *`compound-statement`* **`__except (`** *`expression`* **`)`** *`compound-statement`*

*`try-finally-statement`*: /\* Microsoft-specific \*/<br/>
&emsp;**`__try`** *`compound-statement`* **`__finally`** *`compound-statement`*

1 The **`__leave`** keyword is only valid within the **`__try`** block of a *`try-except-statement`* or a *`try-finally-statement`*.

## See also

[Phrase Structure Grammar](../c-language/phrase-structure-grammar.md)
[Phrase structure grammar](../c-language/phrase-structure-grammar.md)
Loading