这是我的full code,我自定义异常,如:
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();
};
};
并将其继承为:
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’
,我有以下问题:
答案 0 :(得分:6)
由于c ++ 11 what()
noexcept 。您尚未将其声明为 noexcept 。这就是'更宽松的指定者'告诉你。见http://en.cppreference.com/w/cpp/error/exception/what。
即。声明它像
virtual const char *what() const noexcept override