测试 __try, __finally, __except
2015-12-30 23:45
295 查看
C语言标准是没有 try-catch语法 的, M$家自己提供了一组.
/// @file ClassroomExamples.c /// @brief 验证C语言的非标准try, catch #include <windows.h> #include <stdlib.h> #include <stdio.h> #include <stddef.h> #include <crtdbg.h> #include <conio.h> void fnTest_TryCatchByM$(); int main(int argc, char *argv[ ], char *envp[ ]) { fnTest_TryCatchByM$(); printf("END, press any key to quit\n"); getchar(); return 0; } void fnTest_TryCatchByM$() { int* p = 0x00000000; // pointer to NULL puts("hello"); /// __try, __finally, __except都不是C标准函数, 是M$自己家的 /// 为了通用性, 还是不用__x函数 /// __try要有配对的__finally或__except, 只能配对一个 __try { puts("in try"); __try { puts("in try"); /// 如果不在__try中, 就C05了 *p = 13; // causes an access violation exception; } __finally { /// 被__finally捕获的异常, 还会被上一级的__except捕获 /// 反之不行(先被__except捕获, 不会再被上一级的__finally捕获) puts("in finally"); } } /// 当异常发生时, 至少要被一个__except捕获, 否则C05 /// 进不了对应的__finally /// 最外层的异常捕获必须是__except, 如果是__finally /// 否则异常发生时, 会C05 __except(puts("in filter"), 1) { puts("in except"); } puts("world"); }
相关文章推荐
- 蓝懿IOS打飞机游戏练习
- Flask Web开发背景介绍及环境配置
- 闪存浪潮下不得不知的知识(2)-颗粒篇
- Random Walk for Image Segmentation 论文笔记
- android之旅16 自定义广播与无序有序广播
- 闪存浪潮下不得不知的知识(2)-颗粒篇
- jsonp解决CORS问题
- 装饰者模式
- NSMutableString 使用
- 自定义shape
- 链表之单链表约瑟夫问题(一)
- ajax提交json数据,后台解析问题
- Caffe + Ubuntu 14.04 64bit + CUDA6.5 + 无GPU 配置
- Fragment android碎片化管理
- 设计模式六大原则
- linux实战案例作业(1)
- JQuery以JSON方式提交数据到服务端
- 使用运行时函数实现方法交换
- 记住:用户不是傻*,她是你的老婆大人
- 抽象工厂模式