Register__ 2022-02-19 21:08 采纳率: 89.5%
浏览 29
已结题

C++自定义异常类报错

因为异常这个知识点好久没用,有点忘记了(我初学),打算给之前写的东西弄个自定义异常,练习一下就当复习了

class Treeexception : public exception {
    string error_str;
public:
    Treeexception(const char* ex){
        error_str = ex;
    }
    Treeexception(string ex){
        error_str = ex;
    }
    const char* what() const throw(){
        return this->error_str.c_str();
    }
    virtual ~Treeexception(){}
};

打算测试一下


    void func() throw(Treeexception) {
        throw Treeexception("test !");
    }

然后 报错 :

img

  • 写回答

1条回答 默认 最新

  • _GX_ 2022-02-19 21:20
    关注

    C++11不赞成使用Dynamic Exception Specification,C++17已经不支持Dynamic Exception Specification
    https://en.cppreference.com/w/cpp/language/except_spec

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 2月27日
  • 已采纳回答 2月19日
  • 创建了问题 2月19日