【发布时间】:2018-12-03 16:56:38
【问题描述】:
如果 rad 是负数,我需要抛出 std::exeption,我该如何抛出?
void Circle::setRad(double rad) {
if (rad < 0)
{
throw(std::exception );
}
radius = rad;
}
【问题讨论】:
如果 rad 是负数,我需要抛出 std::exeption,我该如何抛出?
void Circle::setRad(double rad) {
if (rad < 0)
{
throw(std::exception );
}
radius = rad;
}
【问题讨论】:
通常你应该抛出一个派生类:
throw std::invalid_argument("radius must be nonnegative");
【讨论】: