Last change
on this file since 21449 was 21449, checked in by dmik, 15 years ago |
testapp: Added test case for for try/finally/leave.
|
File size:
1.5 KB
|
Line | |
---|
1 | #include <stdio.h>
|
---|
2 | #include <windows.h>
|
---|
3 | #include <excpt.h>
|
---|
4 |
|
---|
5 | #ifndef _MSC_VER
|
---|
6 |
|
---|
7 | #include <odinlx.h>
|
---|
8 |
|
---|
9 | int _main();
|
---|
10 | int _argc;
|
---|
11 | char **_argv;
|
---|
12 |
|
---|
13 | int WIN32API WinMain(HANDLE hInstance,
|
---|
14 | HANDLE hPrevInstance,
|
---|
15 | LPSTR lpCmdLine,
|
---|
16 | int nCmdShow)
|
---|
17 | {
|
---|
18 | return _main(_argc, _argv);
|
---|
19 | }
|
---|
20 |
|
---|
21 | int main(int argc, char **argv)
|
---|
22 | {
|
---|
23 | _argc = argc;
|
---|
24 | _argv = argv;
|
---|
25 | EnableSEH();
|
---|
26 | RegisterLxExe(WinMain, NULL);
|
---|
27 | }
|
---|
28 |
|
---|
29 | #else
|
---|
30 | #define _main main
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | void throw_EXCEPTION_INT_DIVIDE_BY_ZERO()
|
---|
34 | {
|
---|
35 | printf("Throwing EXCEPTION_INT_DIVIDE_BY_ZERO...\n");
|
---|
36 | int x = 0;
|
---|
37 | volatile int y = 4 / x;
|
---|
38 | }
|
---|
39 |
|
---|
40 | int _main(int argc, char **argv)
|
---|
41 | {
|
---|
42 | int code = argc > 1 ? atoi(argv[1]) : 0;
|
---|
43 |
|
---|
44 | __try
|
---|
45 | {
|
---|
46 | switch(code)
|
---|
47 | {
|
---|
48 | case 1:
|
---|
49 | {
|
---|
50 | throw_EXCEPTION_INT_DIVIDE_BY_ZERO();
|
---|
51 | printf("FAILED: Exception was not thrown!\n");
|
---|
52 | return 1;
|
---|
53 | }
|
---|
54 | case 2:
|
---|
55 | {
|
---|
56 | printf("Doing __leave...\n");
|
---|
57 | __leave;
|
---|
58 | printf("FAILED: __leave didn't work!\n");
|
---|
59 | return 1;
|
---|
60 | }
|
---|
61 | case 3:
|
---|
62 | default:
|
---|
63 | {
|
---|
64 | printf("Not causing exceptions, not doing __leave...\n");
|
---|
65 | break;
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 | __finally
|
---|
70 | {
|
---|
71 | // handle exception
|
---|
72 | printf("Finally block executed.\n");
|
---|
73 | }
|
---|
74 |
|
---|
75 | printf("Return.\n");
|
---|
76 |
|
---|
77 | return 0;
|
---|
78 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.