Compiler Warning (level 1) C4297

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

A function contains a nothrow declaration and one or more throw statements. To resolve C4297, do not attempt to throw exceptions in functions that are declared with nothrow or to remove the nothrow specification.

For more information on exception specifications, see Exception Specifications. 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

Community Additions