#include <iostream>
#include <stdexcept>
#include <bitset>
using namespace std;
void test_exception(){
int flag = 10;
int i;
cin >> i;
if( i != flag ){
throw runtime_error("输入的数字不等于10");
}
cout << i << endl;
}
void test_try_catch() {
int i , j;
cin >> i >> j;
try {
if( i != j ){
throw runtime_error("not same!");
} else {
cout << "same" << endl;
}
} catch (runtime_error e) {
cout << "error:" <<e.what() << endl;
}
cout << "end" << endl;
}
void test_6_2_3(){
bitset<100> b;
b.set();
try {
b.to_ulong();
} catch (overflow_error e) {
cout << e.what() << endl;
cout << "长度太长" << endl;
} catch(runtime_error e){
cout << "是否能执行这里的代码?" << endl; // no
}
}
int main() {
test_6_2_3();
return 0;
}
异常
最新推荐文章于 2023-08-22 14:39:43 发布