deriving from std::exception

N

Noah Roberts

I am having some problems with deriving the std::exception class. My
compiler (g++-2.95) works with it just fine, but it does in a lot of
broken cases. I have a user/developer that can't compile the following
code:

class CFENException : public std::exception
{
std::string _what;

public:
CFENException(std::string what) : _what(what) {}
virtual const char* what() const throw() { return _what.c_str(); }
};

He is getting the following error from dev-c++ 4.9.8.1:
line 57 in BitBoard.h: looser throw specifier for 'virtual
line 54 in exception: overriding 'virtual

Isn't throw() the tightest specifier you can get? It says this method
cannot throw anything right?

My book on the c++ std, The C++ Standard Library by Josuttis, says the
above is the correct way to derive the exception class. So WTF am I
doing wrong if anything?

Thanks for any help,
NR
 
A

Alexander Terekhov

Noah said:
I am having some problems with deriving the std::exception class. My
compiler (g++-2.95) works with it just fine, but it does in a lot of
broken cases. I have a user/developer that can't compile the following
code:

class CFENException : public std::exception
{
std::string _what;

public:
CFENException(std::string what) : _what(what) {}

Add ~CFENException() throw() {}
virtual const char* what() const throw() { return _what.c_str(); }

what() is brain-damaged.

Almost the entire C++ EH just sucks miserably, BTW.

regards,
alexander.
 
G

Greg P.

| I very much doubt it. If it really does, please post some quote
| here. And possibly also mail a bug-report to the author.
What page(s) is this on?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top