【发布时间】:2020-10-01 14:37:30
【问题描述】:
else
{
// figure out how to fo out of range excetpion.
throw std::out_of_range("An exception occurred: Grade must be between 0.000000 and 100.000000");
//throw std::out_of_range("Grade points must be between 0.000000 and 100.000000.");
}
我得到错误:
Percentage grade: 10000
terminate called after throwing an instance of 'std::out_of_range'
what(): An exception occurred: Grade must be between 0.000000 and 100.000000"
如何删除这个?:
terminate called after throwing an instance of'std::out_of_range'
what():"
【问题讨论】:
-
FWIW,你真的不应该使用异常。错误的输入并没有什么特别之处,你应该只在某些事情真正异常时才使用异常。对于错误的输入,您应该使用错误代码或只是在输入正确数据之前不会停止的循环。
-
catch异常。
标签: c++ throw outofrangeexception