读书人

错误捕获-编译开关EHsc、EHa、EHs

发布时间: 2013-08-11 22:22:29 作者: rapoo

异常捕获--编译开关EHsc、EHa、EHs
// compiler_options_EHA.cpp// compile with: /EHa#include <iostream>#include <excpt.h>using namespace std; void fail() { // generates SE and attempts to catch it using catch(...) try { int i = 0, j = 1; j /= i; // This will throw a SE (divide by zero). } catch(...) { // catch block will only be executed under /EHa cout<<"Caught an exception in catch(...)."<<endl; }} int main() { __try { fail(); } // __except will only catch an exception here __except(EXCEPTION_EXECUTE_HANDLER) { // if the exception was not caught by the catch(...) inside fail() cout << "An exception was caught in __except." << endl; }}

?

?

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

See?_set_se_translator?forexception handling restrictions under?/clr.

The option can be cleared by the symbol?-. For example,?/EHsc-?is interpreted as?/EHs /EHc-?and is equivalent to?/EHs.

See?Exception Handling: Default Synchronous Exception Model?for more information.

To set this compiler option in the Visual Studio developmentenvironment

1.??????Open the project's?Property Pages?dialog box. For details, see?How to: OpenProject Property Pages.

2.??????Click the?C/C++?folder.

3.??????Click the?Code Generation?property page.

4.??????Modify the?Enable C++ Exceptions?property.

Alternately, you can use the following procedure:

To set this compiler option in the Visual Studio developmentenvironment

1.??????Click the?C/C++?folder.

2.??????Click the?Code Generation?property page.

3.??????Set?Enable C++ Exceptions?to?No.

4.??????Click the?Command Line?property page.

5.??????Type the compiler option inthe?Additional Options?box.

To set this compiler option programmatically

????????See?ExceptionHandling.

读书人网 >编程

热点推荐