OSDN Git Service

2004-01-08 Michael Chastain <mec.gnu@mindspring.com>
[pf3gnuchains/pf3gnuchains3x.git] / gdb / testsuite / gdb.cp / exception.cc
1 // Test file for exception handling support.
2
3 #include <iostream.h>
4
5 int foo (int i)
6 {
7   if (i < 32)
8     throw (int) 13;
9   else
10     return i * 2;
11 }
12
13 extern "C" int bar (int k, unsigned long eharg, int flag);
14     
15 int bar (int k, unsigned long eharg, int flag)
16 {
17   cout << "k is " << k << " eharg is " << eharg << " flag is " << flag << endl;
18   return 1;
19 }
20
21 int main()
22 {
23   int j;
24
25   try {
26     j = foo (20);
27   }
28   catch (int x) {
29     cout << "Got an except " << x << endl;
30   }
31   
32   try {
33     try {
34       j = foo (20);
35     }
36     catch (int x) {
37       cout << "Got an except " << x << endl;
38       throw;
39     }
40   }
41   catch (int y) {
42     cout << "Got an except (rethrown) " << y << endl;
43   }
44
45   // Not caught 
46   foo (20);
47   
48 }