- Main Page
- Classes
- Files
- Related Pages

# scexception.h

    00001 //
    00002 // scexception.h
    00003 //
    00004 // Copyright (C) 1996 Limit Point Systems, Inc.
    00005 //
    00006 // Author: Joseph Kenny <jpkenny@sandia.gov>
    00007 // Maintainer: LPS
    00008 //
    00009 // This file is part of the SC Toolkit.
    00010 //
    00011 // The SC Toolkit is free software; you can redistribute it and/or modify
    00012 // it under the terms of the GNU Library General Public License as published by
    00013 // the Free Software Foundation; either version 2, or (at your option)
    00014 // any later version.
    00015 //
    00016 // The SC Toolkit is distributed in the hope that it will be useful,
    00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00019 // GNU Library General Public License for more details.
    00020 //
    00021 // You should have received a copy of the GNU Library General Public License
    00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
    00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
    00024 //
    00025 // The U.S. Government is granted a limited license as per AL 91-7.
    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     std::ostringstream *elaboration_;
    00056
    00057   public:
    00058     SCException(const char *description = 0,
    00059                 const char *file = 0,
    00060                 int line = 0,
    00061                 const ClassDesc *class_desc = 0,
    00062                 const char *exception_type = "SCException") throw();
    00063     SCException(const SCException&) throw();
    00064     ~SCException() throw();
    00065
    00068     const char* what() const throw();
    00069
    00070     const char *description() const throw() { return description_; }
    00071     const char *file() const throw() { return file_; }
    00072     int line() const throw() { return line_; }
    00073     const ClassDesc *class_desc() const throw() { return class_desc_; }
    00074     const char *exception_type() const throw() { return exception_type_; }
    00075
    00079     std::ostream &elaborate();
    00080 };
    00081
    00082 // ///////////////////////////////////////////////////////////////////////
    00083 // Programming Error Exceptions
    00084
    00087 class ProgrammingError: public SCException {
    00088
    00089   public:
    00090     ProgrammingError(const char *description = 0,
    00091                      const char *file = 0,
    00092                      int line = 0,
    00093                      const ClassDesc *class_desc = 0,
    00094                      const char *exception_type = "ProgrammingError") throw();
    00095     ProgrammingError(const ProgrammingError&) throw();
    00096     ~ProgrammingError() throw();
    00097 };
    00098
    00102 class FeatureNotImplemented: public ProgrammingError {
    00103
    00104   public:
    00105     FeatureNotImplemented(const char *description = 0,
    00106                           const char *file = 0,
    00107                           int line = 0,
    00108                           const ClassDesc *class_desc = 0,
    00109                           const char *exception_type = "FeatureNotImplemented")
    00110         throw();
    00111     FeatureNotImplemented(const FeatureNotImplemented&) throw();
    00112     ~FeatureNotImplemented() throw();
    00113 };
    00114
    00115 // ///////////////////////////////////////////////////////////////////////
    00116 // Input Error Exceptions
    00117
    00122 class InputError: public SCException {
    00123     const char *keyword_;
    00124     char *value_;
    00125
    00126   public:
    00127     InputError(const char *description = 0,
    00128                const char *file = 0,
    00129                int line = 0,
    00130                const char *keyword = 0,
    00131                const char *value = 0,
    00132                const ClassDesc *class_desc = 0,
    00133                const char *exception_type = "InputError") throw();
    00134     InputError(const InputError&) throw();
    00135     ~InputError() throw();
    00136     const char *keyword() const throw() { return keyword_; }
    00137     const char *value() const throw() { return value_; }
    00138 };
    00139
    00140 // ///////////////////////////////////////////////////////////////////////
    00141 // System Exceptions
    00142
    00145 class SystemException: public SCException {
    00146
    00147   public:
    00148     SystemException(const char *description = 0,
    00149                     const char *file = 0,
    00150                     int line = 0,
    00151                     const ClassDesc *class_desc = 0,
    00152                     const char *exception_type = "SystemException") throw();
    00153     SystemException(const SystemException&) throw();
    00154     ~SystemException() throw();
    00155 };
    00156
    00159 class MemAllocFailed: public SystemException {
    00160     size_t nbyte_;
    00161
    00162   public:
    00163     MemAllocFailed(const char *description = 0,
    00164                    const char *file = 0,
    00165                    int line = 0,
    00166                    size_t nbyte = 0,
    00167                    const ClassDesc *class_desc = 0,
    00168                    const char *exception_type = "MemAllocFailed") throw();
    00169     MemAllocFailed(const MemAllocFailed&) throw();
    00170     ~MemAllocFailed() throw();
    00171
    00173     size_t nbyte() const throw() { return nbyte_; }
    00174 };
    00175
    00178 class FileOperationFailed: public SystemException {
    00179   public:
    00180     enum FileOperation { Unknown, OpenR, OpenW, OpenRW,
    00181                          Close, Read, Write, Corrupt, Other };
    00182
    00183   private:
    00184     const char *filename_;
    00185     FileOperation operation_;
    00186
    00187   public:
    00188     FileOperationFailed(const char *description = 0,
    00189                    const char *source_file = 0,
    00190                    int line = 0,
    00191                    const char *filename = 0,
    00192                    FileOperation operation = Unknown,
    00193                    const ClassDesc *class_desc = 0,
    00194                    const char *exception_type = "FileOperationFailed") throw();
    00195     FileOperationFailed(const FileOperationFailed&) throw();
    00196     ~FileOperationFailed() throw();
    00197
    00200     const char * filename() const throw() { return filename_; }
    00201     FileOperation operation() const throw() { return operation_; }
    00202 };
    00203
    00206 class SyscallFailed: public SystemException {
    00207     const char *syscall_;
    00208     int err_;
    00209
    00210   public:
    00211     SyscallFailed(const char *description = 0,
    00212                   const char *source_file = 0,
    00213                   int line = 0,
    00214                   const char *syscall = 0,
    00215                   int err = 0,
    00216                   const ClassDesc *class_desc = 0,
    00217                   const char *exception_type = "SyscallFailed") throw();
    00218     SyscallFailed(const SyscallFailed&) throw();
    00219     ~SyscallFailed() throw();
    00220
    00223     const char * syscall() const throw() { return syscall_; }
    00224     int err() const throw() { return err_; }
    00225 };
    00226
    00227 // ///////////////////////////////////////////////////////////////////////
    00228 // Algorithm Exceptions
    00229
    00233 class AlgorithmException: public SCException {
    00234
    00235   public:
    00236     AlgorithmException(const char *description = 0,
    00237                        const char *file = 0,
    00238                        int line = 0,
    00239                        const ClassDesc *class_desc = 0,
    00240                        const char *exception_type = "AlgorithmException")
    00241         throw();
    00242     AlgorithmException(const AlgorithmException&) throw();
    00243     ~AlgorithmException() throw();
    00244 };
    00245
    00249 class MaxIterExceeded: public AlgorithmException {
    00250     int max_iter_;
    00251
    00252   public:
    00253     MaxIterExceeded(const char *description = 0,
    00254                     const char *file = 0,
    00255                     int line = 0,
    00256                     int maxiter = 0,
    00257                     const ClassDesc *class_desc = 0,
    00258                     const char *exception_type = "MaxIterExceeded") throw();
    00259     MaxIterExceeded(const MaxIterExceeded&) throw();
    00260     ~MaxIterExceeded() throw();
    00261
    00262     int max_iter() const throw() { return max_iter_; }
    00263 };
    00264
    00267 class ToleranceExceeded: public AlgorithmException {
    00268     double tolerance_;
    00269     double value_;
    00270
    00271 public:
    00272     ToleranceExceeded(const char *description = 0,
    00273                       const char *file = 0,
    00274                       int line = 0,
    00275                       double tol=0,
    00276                       double val=0,
    00277                       const ClassDesc *class_desc = 0,
    00278                       const char *exception_type = "ToleranceExceeded") throw();
    00279     ToleranceExceeded(const ToleranceExceeded&) throw();
    00280     ~ToleranceExceeded() throw();
    00281     double tolerance() throw() { return tolerance_; }
    00282     double value() throw() { return value_; }
    00283 };
    00284
    00285 // ///////////////////////////////////////////////////////////////////////
    00286 // Limit Exceeded Exceptions
    00287
    00292 template <class T>
    00293 class LimitExceeded: public SCException {
    00294     T limit_;
    00295     T value_;
    00296
    00297 public:
    00298     LimitExceeded(const char *description,
    00299                   const char *file,
    00300                   int line,
    00301                   T lim,
    00302                   T val,
    00303                   const ClassDesc *class_desc = 0,
    00304                   const char *exception_type = "LimitExceeded") throw():
    00305       SCException(description, file, line, class_desc, exception_type),
    00306       limit_(lim), value_(val)
    00307         {
    00308           try {
    00309               elaborate() << "value:       " << value_
    00310                           << std::endl
    00311                           << "limit:       " << limit_
    00312                           << std::endl;
    00313             }
    00314           catch(...) {
    00315             }
    00316         }
    00317     LimitExceeded(const LimitExceeded&ref) throw():
    00318       SCException(ref),
    00319       limit_(ref.limit_), value_(ref.value_)
    00320         {
    00321         }
    00322     ~LimitExceeded() throw() {}
    00323     T tolerance() throw() { return limit_; }
    00324     T value() throw() { return value_; }
    00325 };
    00326
    00327 }
    00328
    00329 #endif
    00330