]>
Commit | Line | Data |
---|---|---|
186c406b TT |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
3 | Copyright 2008, 2009, 2010 Free Software Foundation, Inc. | |
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 | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | #include <iostream> | |
19 | ||
20 | using namespace std; | |
21 | ||
22 | void dummy () | |
23 | { | |
24 | } | |
25 | ||
26 | class NextOverThrowDerivates | |
27 | { | |
28 | ||
29 | public: | |
30 | ||
31 | ||
32 | // Single throw an exception in this function. | |
33 | void function1 (int val) | |
34 | { | |
35 | throw val; | |
36 | } | |
37 | ||
38 | // Throw an exception in another function. | |
39 | void function2 (int val) | |
40 | { | |
41 | function1 (val); | |
42 | } | |
43 | ||
44 | // Throw an exception in another function, but handle it | |
45 | // locally. | |
46 | void function3 (int val) | |
47 | { | |
48 | { | |
49 | try | |
50 | { | |
51 | function1 (val); | |
52 | } | |
53 | catch (...) | |
54 | { | |
55 | cout << "Caught and handled function1 exception" << endl; | |
56 | } | |
57 | } | |
58 | } | |
59 | ||
60 | void rethrow (int val) | |
61 | { | |
62 | try | |
63 | { | |
64 | function1 (val); | |
65 | } | |
66 | catch (...) | |
67 | { | |
68 | throw; | |
69 | } | |
70 | } | |
71 | ||
72 | void finish (int val) | |
73 | { | |
74 | // We use this to test that a "finish" here does not end up in | |
75 | // this frame, but in the one above. | |
76 | try | |
77 | { | |
78 | function1 (val); | |
79 | } | |
80 | catch (int x) | |
81 | { | |
82 | } | |
83 | function1 (val); // marker for until | |
84 | } | |
85 | ||
86 | void until (int val) | |
87 | { | |
88 | function1 (val); | |
89 | function1 (val); // until here | |
90 | } | |
91 | ||
92 | }; | |
93 | NextOverThrowDerivates next_cases; | |
94 | ||
95 | ||
96 | int main () | |
97 | { | |
98 | int testval = -1; | |
99 | ||
100 | try | |
101 | { | |
102 | next_cases.function1 (0); // Start: first test | |
103 | } | |
104 | catch (int val) | |
105 | { | |
106 | dummy (); | |
107 | testval = val; // End: first test | |
108 | } | |
109 | ||
110 | try | |
111 | { | |
112 | next_cases.function2 (1); // Start: nested throw | |
113 | } | |
114 | catch (int val) | |
115 | { | |
116 | dummy (); | |
117 | testval = val; // End: nested throw | |
118 | } | |
119 | ||
120 | try | |
121 | { | |
122 | // This is duplicated so we can next over one but step into | |
123 | // another. | |
124 | next_cases.function2 (2); // Start: step in test | |
125 | } | |
126 | catch (int val) | |
127 | { | |
128 | dummy (); | |
129 | testval = val; // End: step in test | |
130 | } | |
131 | ||
132 | next_cases.function3 (3); // Start: next past catch | |
133 | dummy (); | |
134 | testval = 3; // End: next past catch | |
135 | ||
136 | try | |
137 | { | |
138 | next_cases.rethrow (4); // Start: rethrow | |
139 | } | |
140 | catch (int val) | |
141 | { | |
142 | dummy (); | |
143 | testval = val; // End: rethrow | |
144 | } | |
145 | ||
146 | try | |
147 | { | |
148 | // Another duplicate so we can test "finish". | |
149 | next_cases.function2 (5); // Start: first finish | |
150 | } | |
151 | catch (int val) | |
152 | { | |
153 | dummy (); | |
154 | testval = val; // End: first finish | |
155 | } | |
156 | ||
157 | // Another test for "finish". | |
158 | try | |
159 | { | |
160 | next_cases.finish (6); // Start: second finish | |
161 | } | |
162 | catch (int val) | |
163 | { | |
164 | dummy (); | |
165 | testval = val; // End: second finish | |
166 | } | |
167 | ||
168 | // Test of "until". | |
169 | try | |
170 | { | |
171 | next_cases.finish (7); // Start: first until | |
172 | } | |
173 | catch (int val) | |
174 | { | |
175 | dummy (); | |
176 | testval = val; // End: first until | |
177 | } | |
178 | ||
179 | // Test of "until" with an argument. | |
180 | try | |
181 | { | |
182 | next_cases.until (8); // Start: second until | |
183 | } | |
184 | catch (int val) | |
185 | { | |
186 | dummy (); | |
187 | testval = val; // End: second until | |
188 | } | |
189 | ||
190 | // Test of "advance". | |
191 | try | |
192 | { | |
193 | next_cases.until (9); // Start: advance | |
194 | } | |
195 | catch (int val) | |
196 | { | |
197 | dummy (); | |
198 | testval = val; // End: advance | |
199 | } | |
200 | ||
201 | testval = 32; // done | |
202 | } | |
203 |