Looser throw specifier for C ++

I get an error message:

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

In the destructor, I had never heard of this before, and some google searches say that it could be a GCC 4 problem, and I would not be sure how to work, since I need GCC 4 to create a universal binary.

My Environment: OS X 10.6, Xcode 3.2.2, GCC 4 for creating a universal binary.

What is the problem?

+7
c ++ gcc compiler-construction xcode
source share
2 answers

I assume CPLAT has a base class? I also assume that you did not put the throw specifier on the CPLAT destructor?

You can put throw(X) (where X is a comma-separated list of exceptions) at the end of the function signature to indicate which exceptions it allowed to throw. If you put throw() as the throw specifier, then this indicates that no exceptions can be thrown from this function. This happens quite often with destructors, since you never want the destructor to throw an exception.

A class that overrides a function that has a throw specifier cannot have a looser throw specifier (a list of additional exceptions) than a redefinable function, since this indicates that the function of the derived class may violate the throw class specifier of the base class'. The absence of a throw specifier means that any exception can be thrown from this function, so it becomes free as it can receive.

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

Edit: By the way, I should add that you probably don't want to use throw specifiers (except throw() for destructors), not knowing that this is what you want. Unlike Java checked exceptions, they do not get caught at compile time, but rather interrupt your program at run time if they break. Therefore, it is better not to use them if you do not know what you are doing.

+12
source share

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

Did you put throw () after declaring ~ CP_Window ()?

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

+5
source share

All Articles