Re: How to correct his error?
James Moe <jimoeDESPAM@sohnen-moe.com> wrote in
news:evadncuO3tfxXQnOnZ2dnUVZ5tSdnZ2d@giganews.com:
Hello,
g++ v4.8.1
linux 3.11.10-11-desktop x86_64
I am trying to compile an old program (from 14 years ago) with my own
equally rusty knowledge of C++. I am stuck on this one error: I have no
idea what "looser throw specifier" means.
The code:
class SimpleException : public exception
This indicates that you have 'using namespace std;' in effect. This is a
bad idea, at least in header files. But this is not the cause of the
error.
{
public:
string what;
Public data is a bad idea as well, in general.
SimpleException(const string & _what) { what = _what; };
};
The error:
$ make
$ g++ -Wall -I. -DLIBIMAP_DEBUG -D_REENTRANT_ -DREENTRANT -c
libimap.cpp
-o libimap.o
In file included from libimap.cpp:26:0:
libimap.h:111:7: error: looser throw specifier for ?virtual
SimpleException::~SimpleException()?
You have to add the following to the SimpleException class:
SimpleException ::~SimpleException() throw () {}
The problem is that std::exception has made a promise to not throw in the
destructor, and this means all derived classes have to made the same
promise. However, by some reason the destructor of std::string, which you
have as a member, has not made this promise, although in the practice I
think it will never throw in any sane implementation. So, you need to
explicitly silence the compiler by telling it you are confident that the
destructor of SimpleException will never throw either.
HTH
Paavo