C++中异常处理的工作方式
来源:互联网 发布:训练口语的软件 编辑:程序博客网 时间:2024/05/22 04:26
#include <iostream>
using namespace std;
class Rainbow{
public:
Rainbow(){cout << "Rainbow() " << endl;}
~Rainbow() { cout << "~Rainbow()" << endl; }
};
void oz(){
Rainbow rb;
for(int i = 0; i < 3; i ++){
cout << "There is no place like home " << endl;
}
throw 47;
throw 11.12f;
cout << "Function continues after throw..." << endl;
}
void main(){
try{
cout << "tornado, witch, munchkins, ..." << endl;
oz();
cout << "try continues after handle the throw..." << endl;
} catch (int) {
cout << "Auntie Em! I had the strangest dream..."
<< endl;
} catch (float) {
cout << "Catch a float exception" << endl;
}
cout << "Main function continues after handling the exception" << endl;
}
输出结果如下:
tornado, witch, munchkins, .
Rainbow()
There is no place like home
There is no place like home
There is no place like home
~Rainbow()
Auntie Em! I had the strangest dream.
Main function continues after handling the exception
以上的输出说明:
没有输出Function continues after throw...说明,在抛出异常之后函数就已经结束,不会再继续向下执行
没有输出try continues after handle the throw...说明在try块中,遇到一个异常后try块中之后的语句也将不再执行,所以之后的异常也不会被检测到;
没有输出Catch a float exception说明在异常处理块中,捕捉到第一个异常之后就会结束之后的catch块处理语句将不会再执行
输出Main function continues after handling the exception说明在try--catch块后程序将按照代码流程一次顺序执行
~Rainbow()输出在Auntie Em! I had the strangest dream之前,说明在抛出异常时候是先进行了数据清理,然后再进行的是数据异常的处理工作
- C++中异常处理的工作方式
- 工作中遇到异常处理的问题
- 工作中遇到的异常处理
- linux C 异常处理的方式
- 程序开发中异常的处理方式
- C++中 异常处理的 实现方式
- 【C#】常见的异常及异常处理方式
- 异常的处理方式
- python 中异常处理方式
- 工作中对异常的处理(1)
- java中异常处理的10中方式
- C语言中字符串的处理方式
- 三层架构的项目中通常异常的处理方式!!!
- 三层架构的项目中通常异常的处理方式
- 工作中客户端返回结果处理方式的记录
- 在struts应用中处理异常的各种方式
- java中异常处理的几种方式
- 在C#中 IPAddresss.Parse 的异常与处理方式
- ARM汇编 宏详解
- 如何设置socket的Connect超时(linux)
- 在杭州的程序员帮下忙啊,刚毕业准备去杭州就业,问下情况
- require和include区别测试 php
- 使用贪心算法实现硬币找零问题
- C++中异常处理的工作方式
- 百度涉足招聘市场:猛挖51job智联墙角
- PHP中编码解码urlencode()、urldecode()、rawurlencode()、rawurldecode()
- RSA算法
- linux c程序中获取shell脚本输出
- 走出用例图误区
- nosql理论基础
- dm642的优化
- 初试MongoDB