/EH (Exception Handling Model)

Specifies the model of exception handling to be used by the compiler and destroys C++ objects that will go out of scope as a result of the exception. If /EH is not specified, the compiler will catch structured and C++ exceptions, but will not destroy C++ objects that will go out of scope as a result of the exception.

Use /EHs to specify the synchronous exception handling model (C++ exception handling without structured exception handling exceptions). If you use /EHs, then your catch clause will not catch asynchronous exceptions. Also, all objects in scope when the asynchronous exception is generated will not be destroyed even if the asynchronous exception is handled. Under /EHs, catch(...) will only catch C++ exceptions. Access violations and System.Exception exceptions will not be caught.

Use /EHa to specify the asynchronous exception handling model (C++ exception handling with structured exception handling exceptions). /EHa may result in a less performant image because the compiler will not optimize a try block as aggressively, even if the compiler does not see a throw.

Use /EHa if you want to catch an exception raised with something other than a throw. The following sample will generate an exception:

The /EHc option requires that /EHs or /EHa is specified. Using /clr (Common Language Runtime Compilation) implies /EHa (/clr /EHa is redundant). The compiler will generate an error if /EHs[c] is used after /clr. Optimizations will not affect this behavior. When an exception is caught, the compiler invokes the class destructor or destructors for the object or objects that are in the same scope as the exception. When an exception is not caught, those destructors are not run.