【问题标题】:c++ exception : throwing std::exception [closed]C++ 异常:抛出 std::exception [关闭]
【发布时间】:2018-12-03 16:56:38
【问题描述】:

如果 rad 是负数,我需要抛出 std::exeption,我该如何抛出?

void Circle::setRad(double rad) {
    if (rad < 0)
    {
        throw(std::exception );
    }
    radius = rad;
}

【问题讨论】:

    标签: c++ exception std


    【解决方案1】:

    通常你应该抛出一个派生类:

    throw std::invalid_argument("radius must be nonnegative");
    

    【讨论】:

      猜你喜欢
      • 2012-06-12
      • 2010-09-13
      • 2011-12-10
      • 1970-01-01
      • 1970-01-01
      • 2014-04-23
      • 1970-01-01
      • 2019-01-06
      • 1970-01-01
      相关资源
      最近更新 更多