您的位置:首页 > 编程语言 > C语言/C++

c++异常捕获和处理

2017-03-14 10:44 225 查看
c++异常捕获和处理

----------

三个关键字:try catch throw

#include <iostream>

#include <string>

using namespace std;

/*计算a/b*/

int div(int a,int b){

if(b==0) throw string("wrong!");

else return a/b;

}

int main()

{

   int a=4;int b=0;

   try{

    int c=div(a,b);

   }

   catch(string &r){

       cout<<r<<endl;

   }
    return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: