deriving from std::exception

Discussion in 'C++' started by Noah Roberts, Jul 31, 2003.

  1. Noah Roberts

    Noah Roberts Guest

    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
    Noah Roberts, Jul 31, 2003
    #1
    1. Advertising

  2. 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.
    Alexander Terekhov, Jul 31, 2003
    #2
    1. Advertising

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


    http://google.com/groups?threadm=
    (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.
    Alexander Terekhov, Jul 31, 2003
    #3
  4. Noah Roberts

    Greg P. Guest

    "Alf P. Steinbach" <> wrote in message
    news:...
    | 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?
    Greg P., Aug 1, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Pantos
    Replies:
    2
    Views:
    3,100
    Derek
    May 20, 2004
  2. JustSomeGuy
    Replies:
    8
    Views:
    1,760
    Michiel Salters
    Jun 10, 2004
  3. Guest
    Replies:
    3
    Views:
    714
    John Harrison
    Aug 8, 2004
  4. Nick Keighley

    deriving from std::runtime_error

    Nick Keighley, Aug 6, 2008, in forum: C++
    Replies:
    2
    Views:
    593
  5. Adrian
    Replies:
    3
    Views:
    619
    Adrian
    May 11, 2009
Loading...

Share This Page