c++throw类型
来源:互联网 发布:烟台java培训班哪个好 编辑:程序博客网 时间:2024/05/29 07:57
1 #include<iostream.h> //包含头文件
2 #include<stdlib.h>
3 double fuc(double x, double y) //定义函数
4 {
5 if(y==0)
6 {
7 throw y; //除数为0,抛出异常
8 }
9 return x/y; //否则返回两个数的商
10 }
11 void main()
12 {
13 double res;
14 try //定义异常
15 {
16 res=fuc(2,3);
17 cout<<"The result of x/y is : "<<res<<endl;
18 res=fuc(4,0); //出现异常
19 }
20 catch(double) //捕获并处理异常
21 {
22 cerr<<"error of dividing zero.\n";
23 exit(1); //异常退出程序
24 }
2 #include<stdlib.h>
3 double fuc(double x, double y) //定义函数
4 {
5 if(y==0)
6 {
7 throw y; //除数为0,抛出异常
8 }
9 return x/y; //否则返回两个数的商
10 }
11 void main()
12 {
13 double res;
14 try //定义异常
15 {
16 res=fuc(2,3);
17 cout<<"The result of x/y is : "<<res<<endl;
18 res=fuc(4,0); //出现异常
19 }
20 catch(double) //捕获并处理异常
21 {
22 cerr<<"error of dividing zero.\n";
23 exit(1); //异常退出程序
24 }
25 }
这里throw的是double类型。
- c++throw类型
- throw抛出的类型
- c#: throw和throw ex的区别
- c++primer throw char*
- [c++] exception with no throw
- throw
- throw()
- throw
- throw
- Throw
- Throw
- C ++ 函数后面加throw()的作用
- C ++ 函数后面加throw()的作用
- C ++ 函数后面加throw()的作用
- C ++ 函数后面加throw()的作用
- C ++ 函数后面加throw()的作用
- C ++ 函数后面加throw()的作用
- C ++ 函数后面加throw()的作用
- <<高质量c++c编程指南>>读书笔记2
- 基于VB2008的winsocket控件网络编程
- 裹在刘翔奥运失利事件上的十六层谜云(转载,这东西,我不做评论。但我讨厌铺天盖地都是他的新闻!!)
- 2012.8.12
- 2012.8.13
- c++throw类型
- 理解redo(4)redo log buffer和LGWR
- 晶体管非门电路
- 背包问题九讲 v1.0
- Spring-MVC入门(一):入门实例
- LinkedIn用一幅图告诉你:工程师最想去的10家硅谷创业公司
- Javascript call and apply
- 通过金矿模型介绍动态规划
- Java环境变量配置