13B 异常处理

//error_handing
/*try{
if(有异常情况)
throw 数据;
}监视数据是否被抛出
catch (类型,变量名){}
catch (类型,变量名){}
catch (类型,变量名){}
*/

include

include

using namespace std;
int main(int argc, char const 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){
cout << "double:" << e << endl;
}
catch(long e){
cout << "long :" << e < }

/catch(int e){
cout << "int :" << e < }
/
catch(...){//如果,还没捕获异常。此句用于接受所有异常

//可接受所有异常。后面的catch将没有作用。。后面再加catch,系统也会报错
}
cout << "if you want to,try to it !" < return 0;

}

你可能感兴趣的:(13B 异常处理)