Search code examples
c++qtwarningsexception-specification

How to get rid of "C++ exception specification ignored" warning


I recently got a dll that has been implemented by others. I have to use it in my application. In the header file of their class they have the function declaration

void func1() throw (CCustomException);

Now when i compile it am getting the warning,

C++ exception specification ignored except to indicate a function is not _declspec(nothrow)

I read the MSDN - Documentation but couldn't understand it clearly. Also, I don't want to disable the warning just because it is showing up. I want to know what I am doing wrong instead of disabling it.

I thought my function, say myfunc() accessing that func1() from the dll doesn't have that Exception specification list. Hence I tried having the corresponding exception specification list in my function too as,

void myfunc1() throw (CCustomException);

But I am still getting the warning. What is that warning is all about and how to get rid of it? I am using Qt 4.5 in Windows XP.


Solution

  • Ok, it is a non-answer, but I would throw away the exception specification and never use it again.

    EDIT: I read too fast, and I didn't see you did not write the class yourself. Best way to get rid of warnings in msvc is via #pragma warning(push) followed by #pragma warning(disable:xxxx) where xxxx is the warning code :

    #ifdef _MSC_VER 
    #pragma warning(push)
    #pragma warning(disable:xxxx)
    #endif 
    
    ...
    
    #ifdef _MSC_VER 
    #pragma warning(pop)
    #endif
    

    EDIT: It is perfectly safe to disable the warning. Exception specifications are evil, and the compiler is only telling you it is disabling them for you. Even if it breaks the standard.