2011-06-28 Yao Qi <yao@codesourcery.com>
[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, 2008, 2009, 2010, 2011
4    Free Software Foundation, Inc.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18    */
19
20
21
22 // Test file for exception handling support.
23
24 using namespace std;
25
26 int foo (int i)
27 {
28   if (i < 32)
29     throw (int) 13;
30   else
31     return i * 2;
32 }
33
34 extern "C" int bar (int k, unsigned long eharg, int flag);
35     
36 int bar (int k, unsigned long eharg, int flag)
37 {
38   return 1;
39 }
40
41 int catcher (int x)
42 {
43   return x;
44 }
45
46 int main()
47 {
48   int j;
49
50   try {
51     j = foo (20);
52   }
53   catch (int x) {
54     catcher (x);
55   }
56   
57   try {
58     try {
59       j = foo (20);
60     }
61     catch (int x) {
62       catcher (x);
63       throw;
64     }
65   }
66   catch (int y) {
67     catcher (y);
68   }
69
70   // Not caught 
71   foo (20);
72 }