Search code examples
c++dllcompiler-warningsdllexport

How to export C++ function as a dll that throws exception?


When I try to export the following function as a dll:

extern "C" __declspec(dllexport) void some_func()
{
  throw std::runtime_error("test throwing exception");
}

Visual C++ 2008 gives me the following warning:

1>.\SampleTrainer.cpp(11) : warning C4297: 'some_func' : function assumed not to throw an exception but does
1>        The function is extern "C" and /EHc was specified

I need to extern "C" because I use Qt QLibrary to load the dll and resolve the function name. Without extern "C" it can't find the some_func() function.


Solution

  • If you are determined to do what the compiler is warning you about, why not just suppress the warning?

    #pragma warning(disable: 4247)