C语言标准是没有 try-catch语法 的, M$家自己提供了一组.
-
- #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;
- puts("hello");
-
-
-
-
- __try
- {
- puts("in try");
- __try
- {
- puts("in try");
-
- *p = 13;
- }
- __finally
- {
-
-
- puts("in finally");
- }
- }
-
-
-
-
-
- __except(puts("in filter"), 1)
- {
- puts("in except");
- }
-
- puts("world");
- }
http://blog.csdn.net/lostspeed/article/details/50438020
测试 __try, __finally, __except(被__finally捕获的异常, 还会被上一级的__except捕获。反之不行)
原文:http://www.cnblogs.com/findumars/p/5187274.html