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 |
|
---|
40 | using namespace std;
|
---|
41 | using namespace sc;
|
---|
42 |
|
---|
43 | ////////////////////////////////////////////////////////////////////////
|
---|
44 | // SCException
|
---|
45 |
|
---|
46 | SCException::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 |
|
---|
84 | SCException::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 |
|
---|
103 | SCException::~SCException() throw()
|
---|
104 | {
|
---|
105 | try{ ExEnv::out0().flush(); ExEnv::err0().flush(); }
|
---|
106 | catch(...) {}
|
---|
107 | delete elaboration_;
|
---|
108 | }
|
---|
109 |
|
---|
110 | const char*
|
---|
111 | SCException::what() const throw()
|
---|
112 | {
|
---|
113 | if (elaboration_) {
|
---|
114 | return elaboration_->str().c_str();
|
---|
115 | }
|
---|
116 | return description_;
|
---|
117 | }
|
---|
118 |
|
---|
119 | std::ostream &
|
---|
120 | SCException::elaborate()
|
---|
121 | {
|
---|
122 | if (!elaboration_) {
|
---|
123 | throw std::runtime_error("SCException::elaborate(): cannot elaborate");
|
---|
124 | }
|
---|
125 | return *elaboration_;
|
---|
126 | }
|
---|
127 |
|
---|
128 | ////////////////////////////////////////////////////////////////////////
|
---|
129 | // InputError
|
---|
130 |
|
---|
131 | InputError::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 |
|
---|
165 | InputError::InputError(const InputError& ref) throw():
|
---|
166 | SCException(ref),
|
---|
167 | keyword_(ref.keyword_)
|
---|
168 | {
|
---|
169 | }
|
---|
170 |
|
---|
171 | InputError::~InputError() throw()
|
---|
172 | {
|
---|
173 | delete[] value_;
|
---|
174 | }
|
---|
175 |
|
---|
176 | ////////////////////////////////////////////////////////////////////////
|
---|
177 | // ProgrammingError
|
---|
178 |
|
---|
179 | ProgrammingError::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 |
|
---|
189 | ProgrammingError::ProgrammingError(const ProgrammingError& ref) throw():
|
---|
190 | SCException(ref)
|
---|
191 | {
|
---|
192 | }
|
---|
193 |
|
---|
194 | ProgrammingError::~ProgrammingError() throw()
|
---|
195 | {
|
---|
196 | }
|
---|
197 |
|
---|
198 | ////////////////////////////////////////////////////////////////////////
|
---|
199 | // FeatureNotImplemented
|
---|
200 |
|
---|
201 | FeatureNotImplemented::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 |
|
---|
211 | FeatureNotImplemented::FeatureNotImplemented(const FeatureNotImplemented& ref)
|
---|
212 | throw():
|
---|
213 | ProgrammingError(ref)
|
---|
214 | {
|
---|
215 | }
|
---|
216 |
|
---|
217 | FeatureNotImplemented::~FeatureNotImplemented() throw()
|
---|
218 | {
|
---|
219 | }
|
---|
220 |
|
---|
221 | ////////////////////////////////////////////////////////////////////////
|
---|
222 | // SystemException
|
---|
223 |
|
---|
224 | SystemException::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 |
|
---|
234 | SystemException::SystemException(const SystemException& ref) throw():
|
---|
235 | SCException(ref)
|
---|
236 | {
|
---|
237 | }
|
---|
238 |
|
---|
239 | SystemException::~SystemException() throw()
|
---|
240 | {
|
---|
241 | }
|
---|
242 |
|
---|
243 | ////////////////////////////////////////////////////////////////////////
|
---|
244 | // Memory Allocation Failure
|
---|
245 |
|
---|
246 | MemAllocFailed::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 |
|
---|
266 | MemAllocFailed::MemAllocFailed(const MemAllocFailed& ref) throw():
|
---|
267 | SystemException(ref), nbyte_(ref.nbyte_)
|
---|
268 | {
|
---|
269 | }
|
---|
270 |
|
---|
271 | MemAllocFailed::~MemAllocFailed() throw()
|
---|
272 | {
|
---|
273 | }
|
---|
274 |
|
---|
275 | ////////////////////////////////////////////////////////////////////////
|
---|
276 | // File Operation Failure
|
---|
277 |
|
---|
278 | FileOperationFailed::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 |
|
---|
333 | FileOperationFailed::FileOperationFailed(const FileOperationFailed& ref) throw():
|
---|
334 | SystemException(ref), filename_(ref.filename_), operation_(ref.operation_)
|
---|
335 | {
|
---|
336 | }
|
---|
337 |
|
---|
338 | FileOperationFailed::~FileOperationFailed() throw()
|
---|
339 | {
|
---|
340 | }
|
---|
341 |
|
---|
342 | ////////////////////////////////////////////////////////////////////////
|
---|
343 | // Syscall Failure
|
---|
344 |
|
---|
345 | SyscallFailed::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 |
|
---|
374 | SyscallFailed::SyscallFailed(const SyscallFailed& ref) throw():
|
---|
375 | SystemException(ref), syscall_(ref.syscall_), err_(ref.err_)
|
---|
376 | {
|
---|
377 | }
|
---|
378 |
|
---|
379 | SyscallFailed::~SyscallFailed() throw()
|
---|
380 | {
|
---|
381 | }
|
---|
382 |
|
---|
383 | ////////////////////////////////////////////////////////////////////////
|
---|
384 | // AlgorithmException
|
---|
385 |
|
---|
386 | AlgorithmException::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 |
|
---|
396 | AlgorithmException::AlgorithmException(const AlgorithmException& ref) throw():
|
---|
397 | SCException(ref)
|
---|
398 | {
|
---|
399 | }
|
---|
400 |
|
---|
401 | AlgorithmException::~AlgorithmException() throw()
|
---|
402 | {
|
---|
403 | }
|
---|
404 |
|
---|
405 | ////////////////////////////////////////////////////////////////////////
|
---|
406 | // MaxIterExceeded
|
---|
407 |
|
---|
408 | MaxIterExceeded::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 |
|
---|
426 | MaxIterExceeded::MaxIterExceeded(const MaxIterExceeded& ref) throw():
|
---|
427 | AlgorithmException(ref), max_iter_(ref.max_iter_)
|
---|
428 | {
|
---|
429 | }
|
---|
430 |
|
---|
431 | MaxIterExceeded::~MaxIterExceeded() throw()
|
---|
432 | {
|
---|
433 | }
|
---|
434 |
|
---|
435 | //////////////////////////////////////////////////////////////////////
|
---|
436 | // ToleranceExceeded
|
---|
437 |
|
---|
438 | ToleranceExceeded::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 |
|
---|
458 | ToleranceExceeded::ToleranceExceeded(const ToleranceExceeded& ref) throw():
|
---|
459 | AlgorithmException(ref),
|
---|
460 | tolerance_(ref.tolerance_), value_(ref.value_)
|
---|
461 | {
|
---|
462 | }
|
---|
463 |
|
---|
464 | ToleranceExceeded::~ToleranceExceeded() throw()
|
---|
465 | {
|
---|
466 | }
|
---|