C ++异常:抛出std :: exception

时间:2018-12-03 16:56:39

标签: c++ exception std

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

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

1 个答案:

答案 0 :(得分:1)

通常,您应该抛出派生类之一:

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