Copyright year update in most files of the GDB Project.
[external/binutils.git] / gdb / testsuite / gdb.cp / exception.cc
1 /* This testcase is part of GDB, the GNU debugger.
2
3    Copyright 1997-1998, 2004, 2007-2012 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
19
20
21 // Test file for exception handling support.
22
23 using namespace std;
24
25 int foo (int i)
26 {
27   if (i < 32)
28     throw (int) 13;
29   else
30     return i * 2;
31 }
32
33 extern "C" int bar (int k, unsigned long eharg, int flag);
34     
35 int bar (int k, unsigned long eharg, int flag)
36 {
37   return 1;
38 }
39
40 int catcher (int x)
41 {
42   return x;
43 }
44
45 int main()
46 {
47   int j;
48
49   try {
50     j = foo (20);
51   }
52   catch (int x) {
53     catcher (x);
54   }
55   
56   try {
57     try {
58       j = foo (20);
59     }
60     catch (int x) {
61       catcher (x);
62       throw;
63     }
64   }
65   catch (int y) {
66     catcher (y);
67   }
68
69   // Not caught 
70   foo (20);
71 }