source: ThirdParty/mpqc_open/src/lib/util/class/scextest.cc@ 251420

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 251420 was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 6.7 KB
Line 
1
2#include <util/class/scexception.h>
3#include <stdexcept>
4
5using namespace sc;
6
7class X: public DescribedClass {
8 public:
9 X() {};
10 void x() {
11 throw AlgorithmException("algorithm exception in X::x()",
12 __FILE__,
13 __LINE__,
14 this->class_desc());
15 }
16};
17
18static ClassDesc X_cd(typeid(X),"X",1,"public DescribedClass");
19
20class NestedException: public SCException {
21 public:
22 NestedException(
23 const char *description = 0,
24 const char *file = 0,
25 int line = 0,
26 const ClassDesc *class_desc = 0,
27 const char *exception_type = "NestedException") throw():
28 SCException(description, file, line, class_desc, exception_type)
29 {
30 try {
31 if (description) throw NestedException();
32 throw std::runtime_error("ctor");
33 }
34 catch (...) {}
35 }
36
37 NestedException(const NestedException& ref) throw():
38 SCException(ref)
39 {
40 try {
41 if (description()) throw NestedException();
42 throw std::runtime_error("ctor");
43 }
44 catch (...) {}
45 }
46
47 ~NestedException() throw()
48 {
49 try {
50 if (description()) throw NestedException();
51 throw std::runtime_error("ctor");
52 }
53 catch (...) {}
54 }
55};
56
57void
58f()
59{
60 throw AlgorithmException("algorithm exception in f()",
61 __FILE__,
62 __LINE__
63 );
64}
65
66void
67g()
68{
69 throw MaxIterExceeded("maxiter exception in g()",
70 __FILE__,
71 __LINE__,
72 10);
73}
74
75void
76h()
77{
78 throw ToleranceExceeded("tolerance exception in g()",
79 __FILE__,
80 __LINE__,
81 1.0, 2.0);
82}
83
84void
85i()
86{
87 throw SystemException("system exception in i()",
88 __FILE__,
89 __LINE__
90 );
91}
92
93void
94j()
95{
96 throw MemAllocFailed("memalloc exception in j()",
97 __FILE__,
98 __LINE__,
99 100000);
100}
101
102void
103k()
104{
105 throw ProgrammingError("programming error in k()",
106 __FILE__,
107 __LINE__);
108}
109
110void
111l()
112{
113 throw InputError("input error in l()",
114 __FILE__,
115 __LINE__,
116 "the_keyword",
117 "the_value");
118}
119
120void
121m()
122{
123 throw LimitExceeded<int>("limit exceeded in m()",
124 __FILE__,
125 __LINE__,
126 10, 11);
127}
128
129void
130n()
131{
132 throw FileOperationFailed("file op failed in n()",
133 __FILE__,
134 __LINE__,
135 "outfile",
136 FileOperationFailed::OpenRW);
137}
138
139void
140o()
141{
142 throw SyscallFailed("syscall failed in o()",
143 __FILE__,
144 __LINE__,
145 "xyz",
146 10);
147}
148
149void
150p()
151{
152 throw FeatureNotImplemented("p() not implemented",
153 __FILE__,
154 __LINE__);
155}
156
157void
158ex_on_stack()
159{
160 ProgrammingError ex("programming error in ex_on_stack()",
161 __FILE__, __LINE__);
162 try {
163 ex.elaborate() << "more info about the problem" << std::endl;
164 throw std::runtime_error("whoops");
165 }
166 catch (...) {}
167 throw ex;
168}
169
170void
171nested()
172{
173 throw NestedException("nested exception test",
174 __FILE__, __LINE__);
175}
176
177main()
178{
179 try {
180 f();
181 std::cout << "ERROR: f() ran OK" << std::endl;
182 }
183 catch (SCException &e) {
184 std::cout << "EXPECTED: got an f() exception" << std::endl;
185 std::cout << e.what() << std::endl;
186 }
187
188 try {
189 g();
190 std::cout << "ERROR: g() ran OK" << std::endl;
191 }
192 catch (SCException &e) {
193 std::cout << "EXPECTED: got an g() exception" << std::endl;
194 std::cout << e.what() << std::endl;
195 }
196
197 try {
198 h();
199 std::cout << "ERROR: h() ran OK" << std::endl;
200 }
201 catch (SCException &e) {
202 std::cout << "EXPECTED: got an h() exception" << std::endl;
203 std::cout << e.what() << std::endl;
204 }
205
206 try {
207 i();
208 std::cout << "ERROR: i() ran OK" << std::endl;
209 }
210 catch (SCException &e) {
211 std::cout << "EXPECTED: got an i() exception" << std::endl;
212 std::cout << e.what() << std::endl;
213 }
214
215 try {
216 j();
217 std::cout << "ERROR: j() ran OK" << std::endl;
218 }
219 catch (SCException &e) {
220 std::cout << "EXPECTED: got an j() exception" << std::endl;
221 std::cout << e.what() << std::endl;
222 }
223
224 try {
225 k();
226 std::cout << "ERROR: k() ran OK" << std::endl;
227 }
228 catch (SCException &e) {
229 std::cout << "EXPECTED: got an k() exception" << std::endl;
230 std::cout << e.what() << std::endl;
231 }
232
233 try {
234 l();
235 std::cout << "ERROR: l() ran OK" << std::endl;
236 }
237 catch (SCException &e) {
238 std::cout << "EXPECTED: got an l() exception" << std::endl;
239 std::cout << e.what() << std::endl;
240 }
241
242 try {
243 m();
244 std::cout << "ERROR: m() ran OK" << std::endl;
245 }
246 catch (SCException &e) {
247 std::cout << "EXPECTED: got an m() exception" << std::endl;
248 std::cout << e.what() << std::endl;
249 }
250
251 try {
252 n();
253 std::cout << "ERROR: n() ran OK" << std::endl;
254 }
255 catch (SCException &e) {
256 std::cout << "EXPECTED: got an n() exception" << std::endl;
257 std::cout << e.what() << std::endl;
258 }
259
260 try {
261 o();
262 std::cout << "ERROR: o() ran OK" << std::endl;
263 }
264 catch (SCException &e) {
265 std::cout << "EXPECTED: got an o() exception" << std::endl;
266 std::cout << e.what() << std::endl;
267 }
268
269 try {
270 p();
271 std::cout << "ERROR: p() ran OK" << std::endl;
272 }
273 catch (SCException &e) {
274 std::cout << "EXPECTED: got an p() exception" << std::endl;
275 std::cout << e.what() << std::endl;
276 }
277
278 try {
279 X x;
280 x.x();
281 std::cout << "x.x() ran OK" << std::endl;
282 }
283 catch (SCException &e) {
284 std::cout << "EXPECTED: got an x.x() exception" << std::endl;
285 std::cout << e.what() << std::endl;
286 }
287
288 try {
289 ex_on_stack();
290 std::cout << "ERROR: ex_on_stack() ran OK" << std::endl;
291 }
292 catch (SCException &e) {
293 std::cout << "EXPECTED: got an ex_on_stack() exception" << std::endl;
294 std::cout << e.what() << std::endl;
295 }
296
297 try {
298 nested();
299 std::cout << "ERROR: nested() ran OK" << std::endl;
300 }
301 catch (SCException &e) {
302 std::cout << "EXPECTED: got an nested() exception" << std::endl;
303 std::cout << e.what() << std::endl;
304 }
305
306 return 0;
307}
308
Note: See TracBrowser for help on using the repository browser.