#include <iostream>
using namespace std;
#include <fstream>
int main(int argc, char* argv[])
{
try{
ifstream fin(argv[1]);
if (!fin)
throw 100;
char buf[1000];
fin.read(buf, 1000);
if (!fin)
throw 100.0;
cout.write(buf, 1000);
fin.close();
}
catch(double e){ //exception 异常
cout << "double:" << e << endl;
}
catch(long e){
cout << "long:" << e << endl;
}
catch(...){ //不管什么类型的异常都处理,放在最后一个catch
cout << "exception!" << endl;
}
cout << "what a good day!" << endl;
return 0;
}
异常处理
最新推荐文章于 2025-02-26 17:43:12 发布