Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

looser throw specifier for ‘virtual const char* ro_err::StdErr::what() const’

Tags:

c++

here is my full code, I customize exception like:

class StdErr : public std::exception {

public:
    str msg;

    StdErr(str msg) { this->msg = msg; };

    virtual const char *what() const override {
        return this->msg.c_str();
    };
};

and inherite it like:

class ShErr : public StdErr {

public:
    ShErr(str m) : StdErr(m) { }
};

and use them like:

int main(int argc, char **argv) {
    throw ro_err::ShErr("sh err");
    return (0);
};

it raise looser throw specifier for ‘virtual const char* ro_err::StdErr::what() const’, I have following questions:

  • what is looser?
  • what is specifier?
  • how to fix it
like image 406
chikadance Avatar asked Mar 03 '16 04:03

chikadance


1 Answers

Since c++11 what() is noexcept. You have not declared it as noexcept. That is what the 'looser throw specifier' is telling you. See http://en.cppreference.com/w/cpp/error/exception/what.

I.e. declare it like

virtual const char *what() const noexcept override
like image 58
Captain Giraffe Avatar answered Oct 08 '22 06:10

Captain Giraffe