views:

155

answers:

3

Hi,

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.

+7  A: 

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.

Alexandre C.
It sounds like it's compiling as C++0x, in which exception specifications like this are deprecated, rather than C++03. There may be a compiler option to specify that you want '03, or just to reenable exception specifications if you want other '0x features.
Mike Seymour
@Alexandre C, Ya i agree with disabling and all, but what the warning is all about?? Why it is occurring and what's the rationale behind it?? I just wanted to know these..
liaK
@liaK: see the link posted by Alexandre.
Philipp
@Mike Seymour: Why do you think it's compiling as C++0x? The Visual Studio compiler has _always_ ignored non-empty exception specifications; its been this way since long before deprecation was proposed for C++0x.
Charles Bailey
@Charles: Because I know nothing about Visual Studio. I should have read the linked MSDN page before commenting; it's simply warning about its failure to implement the current standard.
Mike Seymour
@Mike Seymour: Fair enough, it explains your comment. I think if you do use Visual Studio it's fairly common knowledge.
Charles Bailey
A: 

You might try playing with preprocessor:

#ifdef _SOME_MSVC_DEFINE
#  define _throw(foo)
#else
#  define _throw(foo) throw(foo)
#endif

void myfunc1() _throw (CCustomException);

Or, try to disable that warning in Visual Studio.

el.pescado
A: 

I found this link, which I found useful. Just added if it might be helpful to someone..

liaK