标准库异常类定义在4个头文件中:
1.exception头文件定义了最常见的异常类
2.stdexcept头文件定义了几种常见的异常类
3.new头文件定义了bad_alloc异常类型
4.type_info头文件定义了bad_cast异常类型
stdexcept头文件中定义的标准异常类:
exception 最常见的问题
runtime_error 运行时错误:尽在运行时才能检测到的问题
range_error 运行时错误:生成的结果超出了由意思的值域范围
overflow_error 运行时错误:计算上溢
underflow_error 运行时错误:计算下溢
logic_error 逻辑错误:可在运行前检测到得问题
domain_error 逻辑错误:参数的结果值不存在
invalid_argument 逻辑错误:不合适的参数
length_error 逻辑错误:试图生成一个超出该类型最大长度的对象
out_of_range 逻辑错误:使用一个超出有效范围的值
while(){
try{
//execute code that will add the two sales_items
//if the addition fails,the code throws a runtime_error exception
}catch(runtime_errot err){
cout << err.waht();
char c;
cin >> c;
if(cin && c == 'n') break;
}
}
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载