deriving from std::exception

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Noah Roberts

    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(s td::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

  • Alexander Terekhov

    #2
    Re: deriving from std::exception


    Noah Roberts wrote:[color=blue]
    >
    > 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(s td::string what) : _what(what) {}[/color]

    Add ~CFENException( ) throw() {}
    [color=blue]
    > virtual const char* what() const throw() { return _what.c_str(); }[/color]

    what() is brain-damaged.
    [color=blue]
    > };[/color]

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

    regards,
    alexander.

    Comment

    • Alexander Terekhov

      #3
      Re: deriving from std::exception


      "Alf P. Steinbach" wrote:
      [...][color=blue]
      > And possibly also mail a bug-report ...[/color]


      (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.

      Comment

      • Greg P.

        #4
        Re: deriving from std::exception

        "Alf P. Steinbach" <alfps@start.no > wrote in message
        news:3f299c2e.4 08314828@News.C IS.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?


        Comment

        Working...