共用方式為


Compiler Warning (level 1) C4297

 

The latest version of this topic can be found at Compiler Warning (level 1) C4297.

function' : function assumed not to throw an exception but does

A function declaration contains a (possibly implicit) noexcept specifier, an empty throw exception specifier, or a __declspec(nothrow) attribute, and the definition contains one or more throw statements. To resolve C4297, do not attempt to throw exceptions in functions that are declared __declspec(nothrow), noexcept(true) or throw(). Alternatively, remove the noexcept, throw(), or __declspec(nothrow) specification.

By default, the compiler generates implicit noexcept(true) specifiers for user-defined destructors and deallocator functions and compiler-generated special member functions. This conforms to the ISO C++11 standard. To prevent generation of implicit noexcept specifiers and revert the compiler to the non-standard behavior of Visual Studio 2013, use the /Zc:implicitNoexcept- compiler option. For more information, see /Zc:implicitNoexcept (Implicit Exception Specifiers).

For more information on exception specifications, see Exception Specifications (throw). Also, see /EH (Exception Handling Model) for information on how to modify exception handling behavior at compile time.

This warning is also generated for __declspec(dllexport) functions marked extern "C", even if they are C++ functions.

The following sample generates C4297:

// C4297.cpp  
// compile with: /W1 /LD  
void __declspec(nothrow) f1()   // declared nothrow  
// try the following line instead  
// void f1()  
{  
   throw 1;   // C4297  
}