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;
}
----------
三个关键字: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;
}
相关文章推荐
- C++之异常捕获和处理
- 【C++】try 语句捕获异常,catch子句处理异常
- C++异常处理:抛出异常throw,捕获异常catch(...)
- C++异常抛出与捕获及处理
- C++中的异常捕获与处理:Try、Throw、Catch关键字的理解和使用
- c++异常处理,异常声明,捕获异常
- C++异常抛出与捕获及处理
- C++异常抛出与捕获及处理
- c++异常处理,异常声明,捕获异常
- 全局异常捕获处理
- winform中捕获程序未处理的所有异常
- winform中捕获程序未处理的所有异常
- C++、Java和C#中的异常处理
- C++ 异常处理
- C/C++学习----第六章 异常处理
- windows核心编程--SEH(结构异常处理) - C++ Programmer????s Cookbook - C++博客
- Java经验点滴:处理没有被捕获的异常
- c++ 异常处理与错误号之间的选择
- C++ 异常处理 入门
- C与C++中的异常处理4