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

2

7

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.

Revision answered 29/6, 2010 at 13:6 Comment(0)
A
11

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.

Amalia answered 29/6, 2010 at 13:9 Comment(6)
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.Dossier
@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..Revision
@liaK: see the link posted by Alexandre.Archean
@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.Hapsburg
@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.Dossier
@Mike Seymour: Fair enough, it explains your comment. I think if you do use Visual Studio it's fairly common knowledge.Hapsburg
L
0

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.

Linet answered 29/6, 2010 at 13:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.