scexception.h
//
// scexception.h
//
// Copyright (C) 1996 Limit Point Systems, Inc.
//
// Author: Joseph Kenny <jpkenny@sandia.gov>
// Maintainer: LPS
//
// This file is part of the SC Toolkit.
//
// The SC Toolkit is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// The SC Toolkit is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
//
// The U.S. Government is granted a limited license as per AL 91-7.
//
#ifdef __GNUC__
#pragma interface
#endif
#ifndef _util_misc_scexception_h
#define _util_misc_scexception_h
#ifndef _util_class_class_h
#include <util/class/class.h>
#endif
#include <stddef.h>
#include <exception>
#include <sstream>
#include <vector>
namespace sc {
class SCException: public std::exception {
const char *description_;
const char *file_;
int line_;
const ClassDesc* class_desc_;
const char *exception_type_;
std::ostringstream *elaboration_;
public:
SCException(const char *description = 0,
const char *file = 0,
int line = 0,
const ClassDesc *class_desc = 0,
const char *exception_type = "SCException") throw();
SCException(const SCException&) throw();
~SCException() throw();
const char* what() const throw();
const char *description() const throw() { return description_; }
const char *file() const throw() { return file_; }
int line() const throw() { return line_; }
const ClassDesc *class_desc() const throw() { return class_desc_; }
const char *exception_type() const throw() { return exception_type_; }
std::ostream &elaborate();
};
// ///////////////////////////////////////////////////////////////////////
// Programming Error Exceptions
class ProgrammingError: public SCException {
public:
ProgrammingError(const char *description = 0,
const char *file = 0,
int line = 0,
const ClassDesc *class_desc = 0,
const char *exception_type = "ProgrammingError") throw();
ProgrammingError(const ProgrammingError&) throw();
~ProgrammingError() throw();
};
class FeatureNotImplemented: public ProgrammingError {
public:
FeatureNotImplemented(const char *description = 0,
const char *file = 0,
int line = 0,
const ClassDesc *class_desc = 0,
const char *exception_type = "FeatureNotImplemented")
throw();
FeatureNotImplemented(const FeatureNotImplemented&) throw();
~FeatureNotImplemented() throw();
};
// ///////////////////////////////////////////////////////////////////////
// Input Error Exceptions
class InputError: public SCException {
const char *keyword_;
char *value_;
public:
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") throw();
InputError(const InputError&) throw();
~InputError() throw();
const char *keyword() const throw() { return keyword_; }
const char *value() const throw() { return value_; }
};
// ///////////////////////////////////////////////////////////////////////
// System Exceptions
class SystemException: public SCException {
public:
SystemException(const char *description = 0,
const char *file = 0,
int line = 0,
const ClassDesc *class_desc = 0,
const char *exception_type = "SystemException") throw();
SystemException(const SystemException&) throw();
~SystemException() throw();
};
class MemAllocFailed: public SystemException {
size_t nbyte_;
public:
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") throw();
MemAllocFailed(const MemAllocFailed&) throw();
~MemAllocFailed() throw();
size_t nbyte() const throw() { return nbyte_; }
};
class FileOperationFailed: public SystemException {
public:
enum FileOperation { Unknown, OpenR, OpenW, OpenRW,
Close, Read, Write, Corrupt, Other };
private:
const char *filename_;
FileOperation operation_;
public:
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") throw();
FileOperationFailed(const FileOperationFailed&) throw();
~FileOperationFailed() throw();
const char * filename() const throw() { return filename_; }
FileOperation operation() const throw() { return operation_; }
};
class SyscallFailed: public SystemException {
const char *syscall_;
int err_;
public:
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") throw();
SyscallFailed(const SyscallFailed&) throw();
~SyscallFailed() throw();
const char * syscall() const throw() { return syscall_; }
int err() const throw() { return err_; }
};
// ///////////////////////////////////////////////////////////////////////
// Algorithm Exceptions
class AlgorithmException: public SCException {
public:
AlgorithmException(const char *description = 0,
const char *file = 0,
int line = 0,
const ClassDesc *class_desc = 0,
const char *exception_type = "AlgorithmException")
throw();
AlgorithmException(const AlgorithmException&) throw();
~AlgorithmException() throw();
};
class MaxIterExceeded: public AlgorithmException {
int max_iter_;
public:
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") throw();
MaxIterExceeded(const MaxIterExceeded&) throw();
~MaxIterExceeded() throw();
int max_iter() const throw() { return max_iter_; }
};
class ToleranceExceeded: public AlgorithmException {
double tolerance_;
double value_;
public:
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") throw();
ToleranceExceeded(const ToleranceExceeded&) throw();
~ToleranceExceeded() throw();
double tolerance() throw() { return tolerance_; }
double value() throw() { return value_; }
};
// ///////////////////////////////////////////////////////////////////////
// Limit Exceeded Exceptions
template <class T>
class LimitExceeded: public SCException {
T limit_;
T value_;
public:
LimitExceeded(const char *description,
const char *file,
int line,
T lim,
T val,
const ClassDesc *class_desc = 0,
const char *exception_type = "LimitExceeded") throw():
SCException(description, file, line, class_desc, exception_type),
limit_(lim), value_(val)
{
try {
elaborate() << "value: " << value_
<< std::endl
<< "limit: " << limit_
<< std::endl;
}
catch(...) {
}
}
LimitExceeded(const LimitExceeded&ref) throw():
SCException(ref),
limit_(ref.limit_), value_(ref.value_)
{
}
~LimitExceeded() throw() {}
T tolerance() throw() { return limit_; }
T value() throw() { return value_; }
};
}
#endif