Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.cp / nextoverthrow.cc
blob28a95b81b289af30eef122be9601d96a31db8bbc
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2008-2023 Free Software Foundation, Inc.
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.
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.
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/>. */
18 #include <iostream>
20 using namespace std;
22 int dummy ()
24 return 0;
27 class NextOverThrowDerivates
30 public:
33 // Single throw an exception in this function.
34 void function1 (int val)
36 throw val;
39 // Throw an exception in another function.
40 void function2 (int val)
42 function1 (val);
45 // Throw an exception in another function, but handle it
46 // locally.
47 void function3 (int val)
50 try
52 function1 (val);
54 catch (...)
56 cout << "Caught and handled function1 exception" << endl;
61 void rethrow (int val)
63 try
65 function1 (val);
67 catch (...)
69 throw;
73 void finish (int val)
75 // We use this to test that a "finish" here does not end up in
76 // this frame, but in the one above.
77 try
79 function1 (val);
81 catch (int x)
84 function1 (val); // marker for until
87 void until (int val)
89 function1 (val);
90 function1 (val); // until here
93 void resumebpt (int val)
95 try
97 throw val;
99 catch (int x)
101 dummy ();
106 NextOverThrowDerivates next_cases;
110 resumebpt_test (int x)
114 next_cases.resumebpt (x); // Start: resumebpt
115 next_cases.resumebpt (x + 1); // Second: resumebpt
117 catch (int val)
119 dummy ();
120 x = val;
123 return x;
126 int main ()
128 int testval = -1;
132 next_cases.function1 (0); // Start: first test
134 catch (int val)
136 dummy ();
137 testval = val; // End: first test
142 next_cases.function2 (1); // Start: nested throw
144 catch (int val)
146 dummy ();
147 testval = val; // End: nested throw
152 // This is duplicated so we can next over one but step into
153 // another.
154 next_cases.function2 (2); // Start: step in test
156 catch (int val)
158 dummy ();
159 testval = val; // End: step in test
162 next_cases.function3 (3); // Start: next past catch
163 dummy ();
164 testval = 3; // End: next past catch
168 next_cases.rethrow (4); // Start: rethrow
170 catch (int val)
172 dummy ();
173 testval = val; // End: rethrow
178 // Another duplicate so we can test "finish".
179 next_cases.function2 (5); // Start: first finish
181 catch (int val)
183 dummy ();
184 testval = val; // End: first finish
187 // Another test for "finish".
190 next_cases.finish (6); // Start: second finish
192 catch (int val)
194 dummy ();
195 testval = val; // End: second finish
198 // Test of "until".
201 next_cases.finish (7); // Start: first until
203 catch (int val)
205 dummy ();
206 testval = val; // End: first until
209 // Test of "until" with an argument.
212 next_cases.until (8); // Start: second until
214 catch (int val)
216 dummy ();
217 testval = val; // End: second until
220 // Test of "advance".
223 next_cases.until (9); // Start: advance
225 catch (int val)
227 dummy ();
228 testval = val; // End: advance
231 // Test of "resumebpt".
232 testval = resumebpt_test (10);
234 testval = 32; // done