第十章 异常处理和跟踪

2016-11-15  本文已影响0人  ie大博

异常的简单应用

#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;
}
上一篇下一篇

猜你喜欢

热点阅读