2003-08-22 Michael Chastain <mec@shout.net>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / try_catch.cc
1 // 2002-05-27
2
3 #include <exception>
4 #include <stdexcept>
5 #include <string>
6
7 enum region { oriental, egyptian, greek, etruscan, roman };
8
9 // Test one.
10 class gnu_obj_1
11 {
12 public:
13 typedef region antiquities;
14 const bool test;
15 const int key1;
16 long key2;
17
18 antiquities value;
19
20 gnu_obj_1(antiquities a, long l): test(true), key1(5), key2(l), value(a) {}
21 };
22
23 // Test two.
24 template<typename T>
25 class gnu_obj_2: public virtual gnu_obj_1
26 {
27 public:
28 antiquities value_derived;
29
30 gnu_obj_2(antiquities b): gnu_obj_1(oriental, 7), value_derived(b) { }
31 };
32
33 // Test three.
34 template<typename T>
35 class gnu_obj_3
36 {
37 public:
38 typedef region antiquities;
39 gnu_obj_2<int> data;
40
41 gnu_obj_3(antiquities b): data(etruscan) { }
42 };
43
44 int main()
45 {
46 bool test = true;
47 const int i = 5;
48 int j = i;
49 gnu_obj_2<long> test2(roman);
50 gnu_obj_3<long> test3(greek);
51
52 // 1
53 try
54 {
55 ++j;
56 throw gnu_obj_1(egyptian, 4589); // marker 1-throw
57 }
58 catch (gnu_obj_1& obj)
59 {
60 ++j;
61 if (obj.value != egyptian) // marker 1-catch
62 test &= false;
63 if (obj.key2 != 4589)
64 test &= false;
65 }
66 catch (...)
67 {
68 j = 0;
69 test &= false;
70 }
71
72 // 2
73 try
74 {
75 ++j; // marker 2-start
76 try
77 {
78 ++j; // marker 2-next
79 try
80 {
81 ++j;
82 throw gnu_obj_1(egyptian, 4589); // marker 2-throw
83 }
84 catch (gnu_obj_1& obj)
85 {
86 ++j;
87 if (obj.value != egyptian) // marker 2-catch
88 test &= false;
89 if (obj.key2 != 4589)
90 test &= false;
91 }
92 }
93 catch (gnu_obj_1& obj)
94 {
95 ++j;
96 if (obj.value != egyptian)
97 test &= false;
98 if (obj.key2 != 4589)
99 test &= false;
100 }
101 }
102 catch (...)
103 {
104 j = 0;
105 test &= false;
106 }
107
108 // 3 use standard library
109 using namespace std;
110 try
111 {
112 if (j < 100)
113 throw invalid_argument("gdb.1"); // marker 3-throw
114 }
115 catch (exception& obj)
116 {
117 if (obj.what() != "gdb.1") // marker 3-catch
118 test &= false;
119 }
120 return 0;
121 }
This page took 0.044302 seconds and 5 git commands to generate.