Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / testsuite / gdb.cp / try_catch.cc
blob764a6121066e00891c519c6d36fa2ba7902c4e52
1 /* This test script is part of GDB, the GNU debugger.
3 Copyright 2002, 2004,
4 Free Software Foundation, Inc.
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 2 of the License, or
9 (at your option) any later version.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <exception>
22 #include <stdexcept>
23 #include <string>
25 enum region { oriental, egyptian, greek, etruscan, roman };
27 // Test one.
28 class gnu_obj_1
30 public:
31 typedef region antiquities;
32 const bool test;
33 const int key1;
34 long key2;
36 antiquities value;
38 gnu_obj_1(antiquities a, long l): test(true), key1(5), key2(l), value(a) {}
41 // Test two.
42 template<typename T>
43 class gnu_obj_2: public virtual gnu_obj_1
45 public:
46 antiquities value_derived;
48 gnu_obj_2(antiquities b): gnu_obj_1(oriental, 7), value_derived(b) { }
49 };
51 // Test three.
52 template<typename T>
53 class gnu_obj_3
55 public:
56 typedef region antiquities;
57 gnu_obj_2<int> data;
59 gnu_obj_3(antiquities b): data(etruscan) { }
60 };
62 int main()
64 bool test = true;
65 const int i = 5;
66 int j = i;
67 gnu_obj_2<long> test2(roman);
68 gnu_obj_3<long> test3(greek);
70 // 1
71 try
73 ++j;
74 throw gnu_obj_1(egyptian, 4589); // marker 1-throw
76 catch (gnu_obj_1& obj)
78 ++j;
79 if (obj.value != egyptian) // marker 1-catch
80 test &= false;
81 if (obj.key2 != 4589)
82 test &= false;
84 catch (...)
86 j = 0;
87 test &= false;
90 // 2
91 try
93 ++j; // marker 2-start
94 try
96 ++j; // marker 2-next
97 try
99 ++j;
100 throw gnu_obj_1(egyptian, 4589); // marker 2-throw
102 catch (gnu_obj_1& obj)
104 ++j;
105 if (obj.value != egyptian) // marker 2-catch
106 test &= false;
107 if (obj.key2 != 4589)
108 test &= false;
111 catch (gnu_obj_1& obj)
113 ++j;
114 if (obj.value != egyptian)
115 test &= false;
116 if (obj.key2 != 4589)
117 test &= false;
120 catch (...)
122 j = 0;
123 test &= false;
126 // 3 use standard library
127 using namespace std;
130 if (j < 100)
131 throw invalid_argument("gdb.1"); // marker 3-throw
133 catch (exception& obj)
135 if (obj.what() != "gdb.1") // marker 3-catch
136 test &= false;
138 return 0;