00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef __GNUC__
00029 #pragma interface
00030 #endif
00031
00032 #ifndef _util_misc_scexception_h
00033 #define _util_misc_scexception_h
00034
00035 #ifndef _util_class_class_h
00036 #include <util/class/class.h>
00037 #endif
00038
00039 #include <stddef.h>
00040 #include <exception>
00041 #include <sstream>
00042 #include <vector>
00043
00044 namespace sc {
00045
00049 class SCException: public std::exception {
00050 const char *description_;
00051 const char *file_;
00052 int line_;
00053 const ClassDesc* class_desc_;
00054 const char *exception_type_;
00055 mutable char *elaboration_c_str_;
00056 std::ostringstream *elaboration_;
00057
00058 public:
00072 SCException(const char *description = 0,
00073 const char *file = 0,
00074 int line = 0,
00075 const ClassDesc *class_desc = 0,
00076 const char *exception_type = "SCException") throw();
00077 SCException(const SCException&) throw();
00078 ~SCException() throw();
00079
00082 const char* what() const throw();
00083
00086 const char *description() const throw() { return description_; }
00089 const char *file() const throw() { return file_; }
00092 int line() const throw() { return line_; }
00095 const ClassDesc *class_desc() const throw() { return class_desc_; }
00097 const char *exception_type() const throw() { return exception_type_; }
00098
00102 std::ostream &elaborate();
00103 };
00104
00105
00106
00107
00110 class ProgrammingError: public SCException {
00111
00112 public:
00126 ProgrammingError(const char *description = 0,
00127 const char *file = 0,
00128 int line = 0,
00129 const ClassDesc *class_desc = 0,
00130 const char *exception_type = "ProgrammingError") throw();
00131 ProgrammingError(const ProgrammingError&) throw();
00132 ~ProgrammingError() throw();
00133 };
00134
00138 class FeatureNotImplemented: public ProgrammingError {
00139
00140 public:
00154 FeatureNotImplemented(const char *description = 0,
00155 const char *file = 0,
00156 int line = 0,
00157 const ClassDesc *class_desc = 0,
00158 const char *exception_type = "FeatureNotImplemented")
00159 throw();
00160 FeatureNotImplemented(const FeatureNotImplemented&) throw();
00161 ~FeatureNotImplemented() throw();
00162 };
00163
00164
00165
00166
00171 class InputError: public SCException {
00172 const char *keyword_;
00173 char *value_;
00174
00175 public:
00191 InputError(const char *description = 0,
00192 const char *file = 0,
00193 int line = 0,
00194 const char *keyword = 0,
00195 const char *value = 0,
00196 const ClassDesc *class_desc = 0,
00197 const char *exception_type = "InputError") throw();
00198 InputError(const InputError&) throw();
00199 ~InputError() throw();
00201 const char *keyword() const throw() { return keyword_; }
00204 const char *value() const throw() { return value_; }
00205 };
00206
00207
00208
00209
00212 class SystemException: public SCException {
00213
00214 public:
00228 SystemException(const char *description = 0,
00229 const char *file = 0,
00230 int line = 0,
00231 const ClassDesc *class_desc = 0,
00232 const char *exception_type = "SystemException") throw();
00233 SystemException(const SystemException&) throw();
00234 ~SystemException() throw();
00235 };
00236
00239 class MemAllocFailed: public SystemException {
00240 size_t nbyte_;
00241
00242 public:
00257 MemAllocFailed(const char *description = 0,
00258 const char *file = 0,
00259 int line = 0,
00260 size_t nbyte = 0,
00261 const ClassDesc *class_desc = 0,
00262 const char *exception_type = "MemAllocFailed") throw();
00263 MemAllocFailed(const MemAllocFailed&) throw();
00264 ~MemAllocFailed() throw();
00265
00267 size_t nbyte() const throw() { return nbyte_; }
00268 };
00269
00272 class FileOperationFailed: public SystemException {
00273 public:
00274 enum FileOperation { Unknown, OpenR, OpenW, OpenRW,
00275 Close, Read, Write, Corrupt, Other };
00276
00277 private:
00278 const char *filename_;
00279 FileOperation operation_;
00280
00281 public:
00298 FileOperationFailed(const char *description = 0,
00299 const char *source_file = 0,
00300 int line = 0,
00301 const char *filename = 0,
00302 FileOperation operation = Unknown,
00303 const ClassDesc *class_desc = 0,
00304 const char *exception_type = "FileOperationFailed") throw();
00305 FileOperationFailed(const FileOperationFailed&) throw();
00306 ~FileOperationFailed() throw();
00307
00310 const char * filename() const throw() { return filename_; }
00312 FileOperation operation() const throw() { return operation_; }
00313 };
00314
00317 class SyscallFailed: public SystemException {
00318 const char *syscall_;
00319 int err_;
00320
00321 public:
00337 SyscallFailed(const char *description = 0,
00338 const char *source_file = 0,
00339 int line = 0,
00340 const char *syscall = 0,
00341 int err = 0,
00342 const ClassDesc *class_desc = 0,
00343 const char *exception_type = "SyscallFailed") throw();
00344 SyscallFailed(const SyscallFailed&) throw();
00345 ~SyscallFailed() throw();
00346
00349 const char * syscall() const throw() { return syscall_; }
00351 int err() const throw() { return err_; }
00352 };
00353
00354
00355
00356
00360 class AlgorithmException: public SCException {
00361
00362 public:
00376 AlgorithmException(const char *description = 0,
00377 const char *file = 0,
00378 int line = 0,
00379 const ClassDesc *class_desc = 0,
00380 const char *exception_type = "AlgorithmException")
00381 throw();
00382 AlgorithmException(const AlgorithmException&) throw();
00383 ~AlgorithmException() throw();
00384 };
00385
00389 class MaxIterExceeded: public AlgorithmException {
00390 int max_iter_;
00391
00392 public:
00407 MaxIterExceeded(const char *description = 0,
00408 const char *file = 0,
00409 int line = 0,
00410 int maxiter = 0,
00411 const ClassDesc *class_desc = 0,
00412 const char *exception_type = "MaxIterExceeded") throw();
00413 MaxIterExceeded(const MaxIterExceeded&) throw();
00414 ~MaxIterExceeded() throw();
00415
00417 int max_iter() const throw() { return max_iter_; }
00418 };
00419
00422 class ToleranceExceeded: public AlgorithmException {
00423 double tolerance_;
00424 double value_;
00425
00426 public:
00442 ToleranceExceeded(const char *description = 0,
00443 const char *file = 0,
00444 int line = 0,
00445 double tol=0,
00446 double val=0,
00447 const ClassDesc *class_desc = 0,
00448 const char *exception_type = "ToleranceExceeded") throw();
00449 ToleranceExceeded(const ToleranceExceeded&) throw();
00450 ~ToleranceExceeded() throw();
00452 double tolerance() throw() { return tolerance_; }
00454 double value() throw() { return value_; }
00455 };
00456
00457
00458
00459
00464 template <class T>
00465 class LimitExceeded: public SCException {
00466 T limit_;
00467 T value_;
00468
00469 public:
00485 LimitExceeded(const char *description,
00486 const char *file,
00487 int line,
00488 T lim,
00489 T val,
00490 const ClassDesc *class_desc = 0,
00491 const char *exception_type = "LimitExceeded") throw():
00492 SCException(description, file, line, class_desc, exception_type),
00493 limit_(lim), value_(val)
00494 {
00495 try {
00496 elaborate() << "value: " << value_
00497 << std::endl
00498 << "limit: " << limit_
00499 << std::endl;
00500 }
00501 catch(...) {
00502 }
00503 }
00504 LimitExceeded(const LimitExceeded&ref) throw():
00505 SCException(ref),
00506 limit_(ref.limit_), value_(ref.value_)
00507 {
00508 }
00509 ~LimitExceeded() throw() {}
00511 T tolerance() throw() { return limit_; }
00513 T value() throw() { return value_; }
00514 };
00515
00516 }
00517
00518 #endif
00519