是否需要删除引用异常?

时间:2014-05-16 21:58:31

标签: c++ g++

我正在创建自定义的异常类

class my_error: public std::exception
{

public:

    //! Constructs parse error
    my_error(const char* param_msg, std::string param_reason) throw()
    {
        msg = param_msg;
        reason = param_reason;
    }
    ~my_error() throw() {}

private:
    string msg;
    string reason

};

并以这种方式抛出

throw my_error("something wrong", "coffee is too hot");

并抓住

catch(ems_error& ex) { 
// do somehitng here 
}

问题:我应该在这个ex变量上调用delete吗?目前我的程序没有删除工作正常,但我担心内存泄漏

1 个答案:

答案 0 :(得分:5)

异常对象在处理后会自动销毁。 (见C ++11§15.1/ 4)

相关问题