Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

looser throw specifier for in C++

I am getting an error that says:

error: looser throw specifier for 'virtual CPLAT::CP_Window::~CP_Window()'

On the destructor, I have never heard of this before and some Google Searches say this might be a GCC 4 problem, which I would not be sure how to work around since I need GCC 4 to build a Universal Binary.

My Environment: OS X 10.6, XCode 3.2.2, GCC 4 to build a universal binary.

What is the issue?

like image 720
MLS Avatar asked Apr 21 '10 23:04

MLS


2 Answers

I assume that CPLAT has a base class? I'm also guessing that you did not put a throw specifier on CPLAT's destructor?

You can put throw(X) (where X is a comma-separated list of exceptions) at the end of a function's signature to indicate what exceptions it's allowed to throw. If you put throw() as the throw specifier, then it would indicate that no exceptions can be thrown from that function. It's fairly common to do this with destructors since you don't ever want a destructor to throw an exception.

A class that overrides a function which has a throw specifier cannot have a looser throw specifier (list more exceptions) than the function being overridden, since that would indicate that the derived class' function could violate the throw specifier of the base class' function. Not having a throw specifier means that any exception can be thrown from that function, so it's as loose as it can get.

In all likelihood, you need to add throw() to the end of the function signature of CPLAT's destructor.

Edit: By the way, I should probably add that you probably don't want to use throw specifiers (other than throw() on destructors) without really knowing that that's what you want. Unlike Java's checked exceptions, they're not caught at compile-time but rather terminate your program at runtime if violated. So, it's best not to use them unless you know what you're doing.

like image 130
Jonathan M Davis Avatar answered Oct 31 '22 14:10

Jonathan M Davis


http://www.agapow.net/programming/cpp/looser-throw-specifier

Did you put throw() after the declaration of ~CP_Window() ?

Top link in google search "looser throw specifier" BTW.

like image 26
Edward Strange Avatar answered Oct 31 '22 14:10

Edward Strange