]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.mi/mi-catch-cpp-exceptions.cc
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-catch-cpp-exceptions.cc
1 /* Copyright 2019-2024 Free Software Foundation, Inc.
2
3 This file is part of GDB.
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 class my_exception
19 {
20 private:
21 int m_value;
22
23 public:
24 my_exception (int v)
25 : m_value (v)
26 {
27 /* Nothing. */
28 }
29 };
30
31 void
32 bar ()
33 {
34 my_exception ex (4);
35 throw ex; /* Throw 1. */
36 }
37
38 void
39 foo ()
40 {
41 for (int i = 0; i < 2; ++i)
42 {
43 try
44 {
45 bar ();
46 }
47 catch (const my_exception &ex) /* Catch 1. */
48 {
49 if (i == 1)
50 throw; /* Throw 2. */
51 }
52 }
53 }
54
55 int
56 main ()
57 {
58 for (int i = 0; i < 2; ++i)
59 {
60 try
61 {
62 foo ();
63 }
64 catch (const my_exception &ex) /* Catch 2. */
65 {
66 if (i == 1)
67 return 1; /* Stop here. */
68 }
69 }
70
71 return 0;
72 }
73