]>
Commit | Line | Data |
---|---|---|
7cd1089b PM |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
b811d2c2 | 3 | Copyright 2009-2020 Free Software Foundation, Inc. |
7cd1089b PM |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
47d48711 | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
7cd1089b PM |
17 | |
18 | #include <iostream> | |
19 | #include <signal.h> | |
20 | ||
21 | using namespace std; | |
22 | ||
23 | class SimpleException | |
24 | { | |
25 | ||
26 | public: | |
27 | ||
28 | void raise_signal (int dummy) | |
29 | { | |
30 | if (dummy > 0) | |
31 | raise(SIGABRT); | |
32 | } | |
33 | ||
34 | int no_throw_function () | |
35 | { | |
36 | return 1; | |
37 | } | |
38 | ||
39 | void throw_function () | |
40 | { | |
41 | throw 1; | |
42 | } | |
43 | ||
44 | int throw_function_with_handler () | |
45 | { | |
46 | try | |
47 | { | |
48 | throw 1; | |
49 | } | |
50 | catch (...) | |
51 | { | |
52 | cout << "Handled" << endl; | |
53 | } | |
54 | ||
55 | return 2; | |
56 | } | |
57 | ||
58 | void call_throw_function_no_handler () | |
59 | { | |
60 | throw_function (); | |
61 | } | |
62 | ||
63 | void call_throw_function_handler () | |
64 | { | |
65 | throw_function_with_handler (); | |
66 | } | |
67 | }; | |
68 | SimpleException exceptions; | |
69 | ||
70 | int | |
71 | main() | |
72 | { | |
73 | /* Have to call these functions so GCC does not optimize them | |
74 | away. */ | |
75 | exceptions.raise_signal (-1); | |
76 | exceptions.no_throw_function (); | |
77 | exceptions.throw_function_with_handler (); | |
78 | exceptions.call_throw_function_handler (); | |
79 | try | |
80 | { | |
81 | exceptions.throw_function (); | |
82 | exceptions.call_throw_function_no_handler (); | |
83 | } | |
84 | catch (...) | |
85 | { | |
86 | } | |
87 | return 0; | |
88 | } |