/usr/include/sc/util/class/scexception.h is in libsc-dev 2.3.1-16.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | //
// 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 {
/** This is a std::exception specialization that records information
about where an exception took place.
*/
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();
/** Reimplementation of std::exception::what(). The returned
std::string is only valid for the lifetime of this object. */
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_; }
/** Returns a stream where addition information about the exception can
be written. This will throw if a valid stream cannot be returned
(possibly due to low memory). */
std::ostream &elaborate();
};
// ///////////////////////////////////////////////////////////////////////
// Programming Error Exceptions
/** This is thrown when a situations arises that should be impossible.
*/
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();
};
/** This is thrown when an attempt is made to use a feature that
is not yet implemented.
*/
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
/** This is thrown when invalid input is provided. Note that sometimes
input can be internally generated, so what logically would be a
ProgrammingError could result in an InputError being thrown.
*/
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
/** This is thrown when a system problem occurs.
*/
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();
};
/** This is thrown when a memory allocation fails.
*/
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();
/// Returns the number of bytes used in the failed allocation attempt.
size_t nbyte() const throw() { return nbyte_; }
};
/** This is thrown when an operation on a file fails.
*/
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();
/** Returns the file name of the file that caused the error, if known.
Otherwise 0 is returned. */
const char * filename() const throw() { return filename_; }
FileOperation operation() const throw() { return operation_; }
};
/** This is thrown when an system call fails with an errno.
*/
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();
/** Returns the file name of the file that caused the error, if known.
Otherwise 0 is returned. */
const char * syscall() const throw() { return syscall_; }
int err() const throw() { return err_; }
};
// ///////////////////////////////////////////////////////////////////////
// Algorithm Exceptions
/** This exception is thrown whenever a problem with an algorithm is
encountered.
*/
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();
};
/** This is thrown when an iterative algorithm attempts to use more
iterations than allowed.
*/
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_; }
};
/** This is thrown when when some tolerance is exceeded.
*/
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
/** This is thrown when a limit is exceeded. It is more general than
ToleranceExceeded. For problems that are numerical in nature and use
double types, then ToleranceExceeded should be used instead.
*/
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
|