MPQC  3.0.0-alpha
scexception.h
1 //
2 // scexception.h
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 #ifndef _util_misc_scexception_h
29 #define _util_misc_scexception_h
30 
31 #include <stdexcept>
32 #include <util/misc/exception.h>
33 #include <sstream>
34 #include <vector>
35 #include <util/class/class.h>
36 #include <util/misc/bug.h>
37 
38 namespace sc {
39 
43 class SCException: public Exception {
44  const ClassDesc* class_desc_;
45  const char *exception_type_;
46  mutable char *elaboration_c_str_;
47  std::ostringstream *elaboration_;
48  Debugger::Backtrace backtrace_;
49 
50  public:
64  SCException(const char *description = 0,
65  const char *file = 0,
66  int line = 0,
67  const ClassDesc *class_desc = 0,
68  const char *exception_type = "SCException") MPQC__NOEXCEPT;
69  SCException(const SCException&) MPQC__NOEXCEPT;
70  ~SCException() MPQC__NOEXCEPT;
71 
73  const char* what() const MPQC__NOEXCEPT;
74 
77  const ClassDesc *class_desc() const MPQC__NOEXCEPT { return class_desc_; }
79  const char *exception_type() const MPQC__NOEXCEPT { return exception_type_; }
80 
84  std::ostream &elaborate();
85 };
86 
87 // ///////////////////////////////////////////////////////////////////////
88 // Programming Error Exceptions
89 
93 
94  public:
108  ProgrammingError(const char *description = 0,
109  const char *file = 0,
110  int line = 0,
111  const ClassDesc *class_desc = 0,
112  const char *exception_type = "ProgrammingError") MPQC__NOEXCEPT;
113  ProgrammingError(const ProgrammingError&) MPQC__NOEXCEPT;
114  ~ProgrammingError() MPQC__NOEXCEPT;
115 };
116 
121 
122  public:
136  FeatureNotImplemented(const char *description = 0,
137  const char *file = 0,
138  int line = 0,
139  const ClassDesc *class_desc = 0,
140  const char *exception_type = "FeatureNotImplemented")
141  MPQC__NOEXCEPT;
142  FeatureNotImplemented(const FeatureNotImplemented&) MPQC__NOEXCEPT;
143  ~FeatureNotImplemented() MPQC__NOEXCEPT;
144 };
145 
146 // ///////////////////////////////////////////////////////////////////////
147 // Input Error Exceptions
148 
153 class InputError: public SCException {
154  const char *keyword_;
155  char *value_;
156 
157  public:
173  InputError(const char *description = 0,
174  const char *file = 0,
175  int line = 0,
176  const char *keyword = 0,
177  const char *value = 0,
178  const ClassDesc *class_desc = 0,
179  const char *exception_type = "InputError") MPQC__NOEXCEPT;
180  InputError(const InputError&) MPQC__NOEXCEPT;
181  ~InputError() MPQC__NOEXCEPT;
183  const char *keyword() const MPQC__NOEXCEPT { return keyword_; }
186  const char *value() const MPQC__NOEXCEPT { return value_; }
187 };
188 
189 // ///////////////////////////////////////////////////////////////////////
190 // System Exceptions
191 
195 
196  public:
210  SystemException(const char *description = 0,
211  const char *file = 0,
212  int line = 0,
213  const ClassDesc *class_desc = 0,
214  const char *exception_type = "SystemException") MPQC__NOEXCEPT;
215  SystemException(const SystemException&) MPQC__NOEXCEPT;
216  ~SystemException() MPQC__NOEXCEPT;
217 };
218 
222  size_t nbyte_;
223 
224  public:
239  MemAllocFailed(const char *description = 0,
240  const char *file = 0,
241  int line = 0,
242  size_t nbyte = 0,
243  const ClassDesc *class_desc = 0,
244  const char *exception_type = "MemAllocFailed") MPQC__NOEXCEPT;
245  MemAllocFailed(const MemAllocFailed&) MPQC__NOEXCEPT;
246  ~MemAllocFailed() MPQC__NOEXCEPT;
247 
249  size_t nbyte() const MPQC__NOEXCEPT { return nbyte_; }
250 };
251 
255  public:
256  enum FileOperation { Unknown, OpenR, OpenW, OpenRW,
257  Close, Read, Write, Corrupt, Other };
258 
259  private:
260  const char *filename_;
261  FileOperation operation_;
262 
263  public:
280  FileOperationFailed(const char *description = 0,
281  const char *source_file = 0,
282  int line = 0,
283  const char *filename = 0,
284  FileOperation operation = Unknown,
285  const ClassDesc *class_desc = 0,
286  const char *exception_type = "FileOperationFailed") MPQC__NOEXCEPT;
287  FileOperationFailed(const FileOperationFailed&) MPQC__NOEXCEPT;
288  ~FileOperationFailed() MPQC__NOEXCEPT;
289 
292  const char * filename() const MPQC__NOEXCEPT { return filename_; }
294  FileOperation operation() const MPQC__NOEXCEPT { return operation_; }
295 };
296 
300  const char *syscall_;
301  int err_;
302 
303  public:
319  SyscallFailed(const char *description = 0,
320  const char *source_file = 0,
321  int line = 0,
322  const char *syscall = 0,
323  int err = 0,
324  const ClassDesc *class_desc = 0,
325  const char *exception_type = "SyscallFailed") MPQC__NOEXCEPT;
326  SyscallFailed(const SyscallFailed&) MPQC__NOEXCEPT;
327  ~SyscallFailed() MPQC__NOEXCEPT;
328 
331  const char * syscall() const MPQC__NOEXCEPT { return syscall_; }
333  int err() const MPQC__NOEXCEPT { return err_; }
334 };
335 
336 // ///////////////////////////////////////////////////////////////////////
337 // Algorithm Exceptions
338 
343 
344  public:
358  AlgorithmException(const char *description = 0,
359  const char *file = 0,
360  int line = 0,
361  const ClassDesc *class_desc = 0,
362  const char *exception_type = "AlgorithmException")
363  MPQC__NOEXCEPT;
364  AlgorithmException(const AlgorithmException&) MPQC__NOEXCEPT;
365  ~AlgorithmException() MPQC__NOEXCEPT;
366 };
367 
372  int max_iter_;
373 
374  public:
389  MaxIterExceeded(const char *description = 0,
390  const char *file = 0,
391  int line = 0,
392  int maxiter = 0,
393  const ClassDesc *class_desc = 0,
394  const char *exception_type = "MaxIterExceeded") MPQC__NOEXCEPT;
395  MaxIterExceeded(const MaxIterExceeded&) MPQC__NOEXCEPT;
396  ~MaxIterExceeded() MPQC__NOEXCEPT;
397 
399  int max_iter() const MPQC__NOEXCEPT { return max_iter_; }
400 };
401 
405  double tolerance_;
406  double value_;
407 
408 public:
424  ToleranceExceeded(const char *description = 0,
425  const char *file = 0,
426  int line = 0,
427  double tol=0,
428  double val=0,
429  const ClassDesc *class_desc = 0,
430  const char *exception_type = "ToleranceExceeded") MPQC__NOEXCEPT;
431  ToleranceExceeded(const ToleranceExceeded&) MPQC__NOEXCEPT;
432  ~ToleranceExceeded() MPQC__NOEXCEPT;
434  double tolerance() MPQC__NOEXCEPT { return tolerance_; }
436  double value() MPQC__NOEXCEPT { return value_; }
437 };
438 
439 // ///////////////////////////////////////////////////////////////////////
440 // Limit Exceeded Exceptions
441 
446 template <class T>
447 class LimitExceeded: public SCException {
448  T limit_;
449  T value_;
450 
451 public:
468  const char *file,
469  int line,
470  T lim,
471  T val,
472  const ClassDesc *class_desc = 0,
473  const char *exception_type = strdup((std::string("LimitExceeded<") + std::string(typeid(T).name()) + std::string(">")).c_str())
474  ) MPQC__NOEXCEPT:
476  limit_(lim), value_(val)
477  {
478  try {
479  elaborate() << "value: " << value_
480  << std::endl
481  << "limit: " << limit_
482  << std::endl;
483  }
484  catch(...) {
485  }
486  }
487  LimitExceeded(const LimitExceeded&ref) MPQC__NOEXCEPT:
488  SCException(ref),
489  limit_(ref.limit_), value_(ref.value_)
490  {
491  }
492  ~LimitExceeded() MPQC__NOEXCEPT {}
494  T tolerance() MPQC__NOEXCEPT { return limit_; }
496  T value() MPQC__NOEXCEPT { return value_; }
497 };
498 
502 class AssertionFailed : public SCException {
503 
504  const char* assertion_text_;
505 
506  public:
507 
508 
518  AssertionFailed(const char *assertion_text,
519  const char *file,
520  int line) MPQC__NOEXCEPT;
521 
522  const char* assertion_text() const MPQC__NOEXCEPT { return assertion_text_; }
523 
524 };
525 
527 // * MPQC_ASSERT_* macros. Don't use it without these macros.
528 // */
529 //template<typename T1, typename T2>
530 //class VerboseAssertionFailed : public AssertionFailed {
531 
532 // const char* assertion_text_;
533 
534 // public:
535 
536 // typedef enum comparison_operator {
537 // Not=1,
538 // LessThan=2,
539 // GreaterThan=4,
540 // EqualTo=8,
541 // And=16,
542 // Or=32
543 // };
544 
545 
546 // /** Create an AssertionFailed exception.
547 
548 // @param the actual code in the assertion
549 // @param file the file name where the problem occured.
550 // @param line the line number where the exception occured.
551 
552 // It is suggested that the special macros __FILE__ and __LINE__ be
553 // given as the \p file and \p line arguments, respectively.
554 // */
555 // VerboseAssertionFailed(const char *assertion_text,
556 // const char *file,
557 // int line) MPQC__NOEXCEPT;
558 
559 //};
560 
561 }
562 
563 #define __scexception_h_finished
564 #endif
565 
sc::ToleranceExceeded
This is thrown when when some tolerance is exceeded.
Definition: scexception.h:404
sc::SyscallFailed::err
int err() const MPQC__NOEXCEPT
Return the error code that the system call returned.
Definition: scexception.h:333
sc::AssertionFailed
This is thrown when an assertion fails.
Definition: scexception.h:502
sc::Debugger::Backtrace
Creates a backtrace of a running program/thread.
Definition: bug.h:123
sc::SCException::class_desc
const ClassDesc * class_desc() const MPQC__NOEXCEPT
Returns the class descriptor of the object which generated the exception.
Definition: scexception.h:77
sc::SystemException::SystemException
SystemException(const char *description=0, const char *file=0, int line=0, const ClassDesc *class_desc=0, const char *exception_type="SystemException") MPQC__NOEXCEPT
Create a SystemException exception.
sc::Exception::line
int line() const MPQC__NOEXCEPT
Returns the line number where the exception was created.
Definition: exception.h:81
sc::Exception
This is a std::exception specialization that records information about where an exception took place.
Definition: exception.h:48
sc::MemAllocFailed
This is thrown when a memory allocation fails.
Definition: scexception.h:221
sc::FileOperationFailed::operation
FileOperation operation() const MPQC__NOEXCEPT
Return the file operation that failed as a FileOperation enum.
Definition: scexception.h:294
sc::SCException::what
const char * what() const MPQC__NOEXCEPT
overload of Exception::what()
sc::ProgrammingError::ProgrammingError
ProgrammingError(const char *description=0, const char *file=0, int line=0, const ClassDesc *class_desc=0, const char *exception_type="ProgrammingError") MPQC__NOEXCEPT
Create a ProgrammingError exception.
sc::SCException::exception_type
const char * exception_type() const MPQC__NOEXCEPT
Returns the classname of the exception. May return null.
Definition: scexception.h:79
sc::LimitExceeded::value
T value() MPQC__NOEXCEPT
The value which exceeded the limit.
Definition: scexception.h:496
sc::AlgorithmException
This exception is thrown whenever a problem with an algorithm is encountered.
Definition: scexception.h:342
sc::Exception::file
const char * file() const MPQC__NOEXCEPT
Returns the name of the file in which the exception was created.
Definition: exception.h:78
sc::InputError::InputError
InputError(const char *description=0, const char *file=0, int line=0, const char *keyword=0, const char *value=0, const ClassDesc *class_desc=0, const char *exception_type="InputError") MPQC__NOEXCEPT
Create a InputError exception.
sc::SCException
This is a sc::Exception specialization that keeps track of the ClassDesc for the MPQC object from whi...
Definition: scexception.h:43
sc::SyscallFailed
This is thrown when an system call fails with an errno.
Definition: scexception.h:299
sc::InputError::value
const char * value() const MPQC__NOEXCEPT
Return the erroneous value which caused this exception to be thrown.
Definition: scexception.h:186
sc::AssertionFailed::AssertionFailed
AssertionFailed(const char *assertion_text, const char *file, int line) MPQC__NOEXCEPT
Create an AssertionFailed exception.
sc::LimitExceeded::LimitExceeded
LimitExceeded(const char *description, const char *file, int line, T lim, T val, const ClassDesc *class_desc=0, const char *exception_type=strdup((std::string("LimitExceeded<")+std::string(typeid(T).name())+std::string(">")).c_str())) MPQC__NOEXCEPT
Create a LimitExceeded exception.
Definition: scexception.h:467
sc::FileOperationFailed
This is thrown when an operation on a file fails.
Definition: scexception.h:254
sc::InputError
This is thrown when invalid input is provided.
Definition: scexception.h:153
sc::FeatureNotImplemented
This is thrown when an attempt is made to use a feature that is not yet implemented.
Definition: scexception.h:120
sc::FileOperationFailed::filename
const char * filename() const MPQC__NOEXCEPT
Returns the file name of the file that caused the error, if known.
Definition: scexception.h:292
sc::ClassDesc
This class is used to contain information about classes.
Definition: class.h:147
sc::MemAllocFailed::nbyte
size_t nbyte() const MPQC__NOEXCEPT
Returns the number of bytes used in the failed allocation attempt.
Definition: scexception.h:249
sc::LimitExceeded
This is thrown when a limit is exceeded.
Definition: scexception.h:447
sc::SyscallFailed::syscall
const char * syscall() const MPQC__NOEXCEPT
Returns the file name of the file that caused the error, if known.
Definition: scexception.h:331
sc::MaxIterExceeded
This is thrown when an iterative algorithm attempts to use more iterations than allowed.
Definition: scexception.h:371
sc::FeatureNotImplemented::FeatureNotImplemented
FeatureNotImplemented(const char *description=0, const char *file=0, int line=0, const ClassDesc *class_desc=0, const char *exception_type="FeatureNotImplemented") MPQC__NOEXCEPT
Create a FeatureNotImplemented exception.
sc::SystemException
This is thrown when a system problem occurs.
Definition: scexception.h:194
sc::Exception::description
const char * description() const MPQC__NOEXCEPT
Reimplementation of std::exception::what().
Definition: exception.h:75
sc::InputError::keyword
const char * keyword() const MPQC__NOEXCEPT
Return the keyword having an erroneous value.
Definition: scexception.h:183
sc::SCException::SCException
SCException(const char *description=0, const char *file=0, int line=0, const ClassDesc *class_desc=0, const char *exception_type="SCException") MPQC__NOEXCEPT
Create an SCException.
sc::LimitExceeded::tolerance
T tolerance() MPQC__NOEXCEPT
The limit which was exceeded.
Definition: scexception.h:494
sc::ToleranceExceeded::tolerance
double tolerance() MPQC__NOEXCEPT
Return the required tolerance.
Definition: scexception.h:434
sc::MaxIterExceeded::max_iter
int max_iter() const MPQC__NOEXCEPT
Return the maximum number of iterations.
Definition: scexception.h:399
sc::ProgrammingError
This is thrown when a situations arises that should be impossible.
Definition: scexception.h:92
sc::ToleranceExceeded::ToleranceExceeded
ToleranceExceeded(const char *description=0, const char *file=0, int line=0, double tol=0, double val=0, const ClassDesc *class_desc=0, const char *exception_type="ToleranceExceeded") MPQC__NOEXCEPT
Create a ToleranceExceeded exception.
sc::MaxIterExceeded::MaxIterExceeded
MaxIterExceeded(const char *description=0, const char *file=0, int line=0, int maxiter=0, const ClassDesc *class_desc=0, const char *exception_type="MaxIterExceeded") MPQC__NOEXCEPT
Create a MaxIterExceeded exception.
sc::FileOperationFailed::FileOperationFailed
FileOperationFailed(const char *description=0, const char *source_file=0, int line=0, const char *filename=0, FileOperation operation=Unknown, const ClassDesc *class_desc=0, const char *exception_type="FileOperationFailed") MPQC__NOEXCEPT
Create a FileOperationFailure exception.
sc::ToleranceExceeded::value
double value() MPQC__NOEXCEPT
Return the value which was obtained.
Definition: scexception.h:436
sc::AlgorithmException::AlgorithmException
AlgorithmException(const char *description=0, const char *file=0, int line=0, const ClassDesc *class_desc=0, const char *exception_type="AlgorithmException") MPQC__NOEXCEPT
Create an AlgorithmException.
sc::SCException::elaborate
std::ostream & elaborate()
Returns a stream where additional information about the exception can be written.
sc::SyscallFailed::SyscallFailed
SyscallFailed(const char *description=0, const char *source_file=0, int line=0, const char *syscall=0, int err=0, const ClassDesc *class_desc=0, const char *exception_type="SyscallFailed") MPQC__NOEXCEPT
Create a SyscallFailed exception.
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::MemAllocFailed::MemAllocFailed
MemAllocFailed(const char *description=0, const char *file=0, int line=0, size_t nbyte=0, const ClassDesc *class_desc=0, const char *exception_type="MemAllocFailed") MPQC__NOEXCEPT
Create a MemAllocFailed exception.

Generated at Sun Jan 26 2020 23:24:02 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.