473,320 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

deriving from std::exception

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

Jul 19 '05 #1
3 10987

Noah Roberts wrote:

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.
Jul 19 '05 #2

"Alf P. Steinbach" wrote:
[...]
And possibly also mail a bug-report ...


http://google.com/groups?threadm=3EC...0B266%40web.de
(Subject: Exception handling... it's time to fix the standard)

"I believe that ALL dtors shall have an implicit throw()-
nothing exception-spec imposed on them. "

regards,
alexander.
Jul 19 '05 #3
"Alf P. Steinbach" <al***@start.no> wrote in message
news:3f****************@News.CIS.DFN.DE...
| 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?
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Boogie El Aceitoso | last post by:
Hi, I have an exception class for winapi errors (returns a formated error mesage, usign ::GetLastError() et al, with what()). It looks like this: class WinapiException : public...
2
by: Stefan Pantos | last post by:
Dear all, Could someone explain to me the proper use of throw()? As it is used for std::exception. I cannot find anything which describes how it should be used and all the information about...
3
by: Pierre Rouleau | last post by:
The std::exception class defined in the Standard C++ <exception> header specifies that the constructors could throw any exception becuase they do not have a throw() specification. Why is that? ...
2
by: ma740988 | last post by:
The hierachy for standard exception lists: bad_alloc, bad_cast, bad_typeid, logic_error, ios_base::failure, runtime_error and bad_exception runtime_error and logic_error has subsets. The...
3
by: __PPS__ | last post by:
Hi, I've read in documentation to different libraries that their exception classes aren't subclasses from std::exception, and a separate catch statement is required for their exceptions. Always, I...
4
by: Divick | last post by:
Hi all, I want to subclass std::exception so as to designate the type of error that I want to throw, out of my classes, and for that I need to store the messages inside the exception classes. I...
2
by: Darko Miletic | last post by:
Recently I wrote a dll in c++ and to simplify the distribution I decided to link with multithreaded static library (/MT or /MTd option). In debug everything works fine but in release I get this: ...
5
by: Miles | last post by:
Hello all, When I subclass std::exception and throw an instance of the subclass, when I call the what() method of the caught exception, it does not call the overridden method. I'm under the...
3
by: vainstah | last post by:
Hello Guys and Galls, To start off, I have reached the solution I was looking for, but I would like comments and feedback on the solution I have reached and tips/tricks on making it more elegant....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.