source: ThirdParty/mpqc_open/src/lib/util/class/scexception.cc@ 398fcd

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 398fcd 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: 11.8 KB
Line 
1//
2// scexception.cc
3//
4// Copyright (C) 1996 Limit Point Systems, Inc.
5//
6// Author: Joseph Kenny <jpkenny@sandia.gov>
7// Maintainer: LPS
8//
9// This file is part of the SC Toolkit.
10//
11// The SC Toolkit is free software; you can redistribute it and/or modify
12// it under the terms of the GNU Library General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// The SC Toolkit is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Library General Public License for more details.
20//
21// You should have received a copy of the GNU Library General Public License
22// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28#ifdef __GNUC__
29#pragma implementation
30#endif
31
32#include <errno.h>
33#include <string.h>
34
35#include <stdexcept>
36#include <sstream>
37#include <util/state/stateio.h>
38#include <util/class/scexception.h>
39
40using namespace std;
41using namespace sc;
42
43////////////////////////////////////////////////////////////////////////
44// SCException
45
46SCException::SCException(const char *description,
47 const char *file,
48 int line,
49 const ClassDesc *class_desc,
50 const char *exception_type) throw():
51 description_(description),
52 file_(file),
53 line_(line),
54 class_desc_(class_desc),
55 exception_type_(exception_type)
56{
57 try {
58 elaboration_ = new ostringstream;
59 if (exception_type_) {
60 elaborate() << "exception: " << exception_type_
61 << std::endl;
62 }
63 if (description_) {
64 elaborate() << "description: " << description
65 << std::endl;
66 }
67 if (file_) {
68 elaborate() << "location: " << file << ":" << line
69 << std::endl;
70 }
71 if (class_desc_) {
72 elaborate() << "class: " << class_desc_->name()
73 << std::endl;
74 }
75 }
76 catch (...) {
77 // info in the elaboration is incomplete, so delete it
78 // and at least the basic description will be available
79 delete elaboration_;
80 elaboration_ = 0;
81 }
82}
83
84SCException::SCException(const SCException& ref) throw():
85 description_(ref.description_),
86 file_(ref.file_),
87 line_(ref.line_),
88 class_desc_(ref.class_desc_)
89{
90 elaboration_ = 0;
91 if (ref.elaboration_) {
92 try {
93 elaboration_ = new ostringstream;
94 elaborate() << ref.elaboration_->str();
95 }
96 catch (...) {
97 delete elaboration_;
98 elaboration_ = 0;
99 }
100 }
101}
102
103SCException::~SCException() throw()
104{
105 try{ ExEnv::out0().flush(); ExEnv::err0().flush(); }
106 catch(...) {}
107 delete elaboration_;
108}
109
110const char*
111SCException::what() const throw()
112{
113 if (elaboration_) {
114 return elaboration_->str().c_str();
115 }
116 return description_;
117}
118
119std::ostream &
120SCException::elaborate()
121{
122 if (!elaboration_) {
123 throw std::runtime_error("SCException::elaborate(): cannot elaborate");
124 }
125 return *elaboration_;
126}
127
128////////////////////////////////////////////////////////////////////////
129// InputError
130
131InputError::InputError(
132 const char *description,
133 const char *file,
134 int line,
135 const char *keyword,
136 const char *value,
137 const ClassDesc *class_desc,
138 const char *exception_type) throw():
139 SCException(description, file, line, class_desc, exception_type),
140 keyword_(keyword)
141{
142 try {
143 if (value) {
144 value_ = new char[strlen(value)+1];
145 if (value_) strcpy(value_, value);
146 }
147 else {
148 value_ = 0;
149 }
150 }
151 catch (...) {
152 value_ = 0;
153 }
154
155 try {
156 if (keyword_)
157 elaborate() << "keyword: " << keyword_ << std::endl;
158 if (value_)
159 elaborate() << "value: " << value_ << std::endl;
160 }
161 catch (...) {
162 }
163}
164
165InputError::InputError(const InputError& ref) throw():
166 SCException(ref),
167 keyword_(ref.keyword_)
168{
169}
170
171InputError::~InputError() throw()
172{
173 delete[] value_;
174}
175
176////////////////////////////////////////////////////////////////////////
177// ProgrammingError
178
179ProgrammingError::ProgrammingError(
180 const char *description,
181 const char *file,
182 int line,
183 const ClassDesc *class_desc,
184 const char *exception_type) throw():
185 SCException(description, file, line, class_desc, exception_type)
186{
187}
188
189ProgrammingError::ProgrammingError(const ProgrammingError& ref) throw():
190 SCException(ref)
191{
192}
193
194ProgrammingError::~ProgrammingError() throw()
195{
196}
197
198////////////////////////////////////////////////////////////////////////
199// FeatureNotImplemented
200
201FeatureNotImplemented::FeatureNotImplemented(
202 const char *description,
203 const char *file,
204 int line,
205 const ClassDesc *class_desc,
206 const char *exception_type) throw():
207 ProgrammingError(description, file, line, class_desc, exception_type)
208{
209}
210
211FeatureNotImplemented::FeatureNotImplemented(const FeatureNotImplemented& ref)
212 throw():
213 ProgrammingError(ref)
214{
215}
216
217FeatureNotImplemented::~FeatureNotImplemented() throw()
218{
219}
220
221////////////////////////////////////////////////////////////////////////
222// SystemException
223
224SystemException::SystemException(
225 const char *description,
226 const char *file,
227 int line,
228 const ClassDesc *class_desc,
229 const char *exception_type) throw():
230 SCException(description, file, line, class_desc, exception_type)
231{
232}
233
234SystemException::SystemException(const SystemException& ref) throw():
235 SCException(ref)
236{
237}
238
239SystemException::~SystemException() throw()
240{
241}
242
243////////////////////////////////////////////////////////////////////////
244// Memory Allocation Failure
245
246MemAllocFailed::MemAllocFailed(const char *description,
247 const char *file,
248 int line,
249 size_t nbyte,
250 const ClassDesc *class_desc,
251 const char *exception_type) throw():
252 SystemException(description, file, line, class_desc, exception_type),
253 nbyte_(nbyte)
254{
255 try {
256 if (nbyte_) {
257 elaborate() << "nbyte: "
258 << nbyte
259 << std::endl;
260 }
261 }
262 catch(...) {
263 }
264}
265
266MemAllocFailed::MemAllocFailed(const MemAllocFailed& ref) throw():
267 SystemException(ref), nbyte_(ref.nbyte_)
268{
269}
270
271MemAllocFailed::~MemAllocFailed() throw()
272{
273}
274
275////////////////////////////////////////////////////////////////////////
276// File Operation Failure
277
278FileOperationFailed::FileOperationFailed(const char *description,
279 const char *file,
280 int line,
281 const char *filename,
282 FileOperation op,
283 const ClassDesc *class_desc,
284 const char *exception_type) throw():
285 SystemException(description, file, line, class_desc, exception_type),
286 filename_(filename),
287 operation_(op)
288{
289 try {
290 if (filename_) {
291 elaborate() << "file name: "
292 << filename_
293 << std::endl;
294 }
295 elaborate() << "file op: ";
296 switch (operation_) {
297 case Unknown:
298 elaborate() << "Unknown";
299 break;
300 case OpenR:
301 elaborate() << "OpenR";
302 break;
303 case OpenW:
304 elaborate() << "OpenW";
305 break;
306 case OpenRW:
307 elaborate() << "OpenRW";
308 break;
309 case Close:
310 elaborate() << "Close";
311 break;
312 case Read:
313 elaborate() << "Read";
314 break;
315 case Write:
316 elaborate() << "Write";
317 break;
318 case Corrupt:
319 elaborate() << "Corrupt";
320 break;
321 case Other:
322 elaborate() << "Other";
323 break;
324 default:
325 elaborate() << "Invalid";
326 }
327 elaborate() << std::endl;
328 }
329 catch(...) {
330 }
331}
332
333FileOperationFailed::FileOperationFailed(const FileOperationFailed& ref) throw():
334 SystemException(ref), filename_(ref.filename_), operation_(ref.operation_)
335{
336}
337
338FileOperationFailed::~FileOperationFailed() throw()
339{
340}
341
342////////////////////////////////////////////////////////////////////////
343// Syscall Failure
344
345SyscallFailed::SyscallFailed(const char *description,
346 const char *file,
347 int line,
348 const char *syscall,
349 int err,
350 const ClassDesc *class_desc,
351 const char *exception_type) throw():
352 SystemException(description, file, line, class_desc, exception_type),
353 syscall_(syscall),
354 err_(err)
355{
356 try {
357 if (err_ == 0) {
358 err_ = errno;
359 }
360 if (syscall_) {
361 elaborate() << "system call: "
362 << syscall_
363 << std::endl;
364 }
365 elaborate() << "error: "
366 << strerror(err_)
367 << " (" << err_ << ")"
368 << std::endl;
369 }
370 catch(...) {
371 }
372}
373
374SyscallFailed::SyscallFailed(const SyscallFailed& ref) throw():
375 SystemException(ref), syscall_(ref.syscall_), err_(ref.err_)
376{
377}
378
379SyscallFailed::~SyscallFailed() throw()
380{
381}
382
383////////////////////////////////////////////////////////////////////////
384// AlgorithmException
385
386AlgorithmException::AlgorithmException(
387 const char *description,
388 const char *file,
389 int line,
390 const ClassDesc *class_desc,
391 const char *exception_type) throw():
392 SCException(description, file, line, class_desc, exception_type)
393{
394}
395
396AlgorithmException::AlgorithmException(const AlgorithmException& ref) throw():
397 SCException(ref)
398{
399}
400
401AlgorithmException::~AlgorithmException() throw()
402{
403}
404
405////////////////////////////////////////////////////////////////////////
406// MaxIterExceeded
407
408MaxIterExceeded::MaxIterExceeded(const char *description,
409 const char *file,
410 int line,
411 int maxiter,
412 const ClassDesc *class_desc,
413 const char *exception_type) throw():
414 AlgorithmException(description, file, line, class_desc, exception_type),
415 max_iter_(maxiter)
416{
417 try {
418 elaborate() << "max_iter: "
419 << maxiter
420 << std::endl;
421 }
422 catch(...) {
423 }
424}
425
426MaxIterExceeded::MaxIterExceeded(const MaxIterExceeded& ref) throw():
427 AlgorithmException(ref), max_iter_(ref.max_iter_)
428{
429}
430
431MaxIterExceeded::~MaxIterExceeded() throw()
432{
433}
434
435//////////////////////////////////////////////////////////////////////
436// ToleranceExceeded
437
438ToleranceExceeded::ToleranceExceeded(const char *description,
439 const char *file,
440 int line,
441 double tol,
442 double val,
443 const ClassDesc *class_desc,
444 const char *exception_type) throw():
445 AlgorithmException(description, file, line, class_desc, exception_type),
446 tolerance_(tol), value_(val)
447{
448 try {
449 elaborate() << "value: " << value_
450 << std::endl
451 << "tolerance: " << tolerance_
452 << std::endl;
453 }
454 catch(...) {
455 }
456}
457
458ToleranceExceeded::ToleranceExceeded(const ToleranceExceeded& ref) throw():
459 AlgorithmException(ref),
460 tolerance_(ref.tolerance_), value_(ref.value_)
461{
462}
463
464ToleranceExceeded::~ToleranceExceeded() throw()
465{
466}
Note: See TracBrowser for help on using the repository browser.