异常的简单应用
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n=1;
try//这个位置相当于一个判断
{
cout<<"begin"<<endl;
if(n==1)
throw 1;//把一返还给catch
cout<<"after"<<endl;
}
catch(int)//catch接受throw给的内容
{
cout<<"catch"<<endl;
}
// catch(...)//其意义是全都能抓取
cout<<"end"<<endl;
return 0;
}
网友评论