2016-03-03 75 views
3

这里是我的full code,我自定义异常,如:宽松掷符为 '虚拟为const char * ro_err :: STDERR ::什么()const的'

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(); 
    }; 
}; 

和inherite它想:

class ShErr : public StdErr { 

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

,并利用它们喜欢:

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

它提升looser throw specifier for ‘virtual const char* ro_err::StdErr::what() const’,我有以下问题:

  • 什么更松散?
  • 什么是说明者?
  • 如何解决它

回答

5

由于C++ 11 what()是noexcept。您尚未将其宣布为,但不包括。这就是“宽松投标说明者”告诉你的。见http://en.cppreference.com/w/cpp/error/exception/what

I.e.宣布它像

virtual const char *what() const noexcept override 
+0

更宽松的是什么意思? – asullaherc

+0

@asullaherc这是一个不太严格的throw规范的定义。没有它,什么()被允许抛出异常。 –