/usr/include/BALL/COMMON/exception.h is in libball1.4-dev 1.4.1+20111206-3.
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 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | // -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_COMMON_EXCEPTION_H
#define BALL_COMMON_EXCEPTION_H
#ifndef BALL_CONFIG_CONFIG_H
# include <BALL/CONFIG/config.h>
#endif
#ifndef BALL_COMMON_GLOBAL_H
# include <BALL/COMMON/global.h>
#endif
#ifdef BALL_COMPILER_MSVC
#pragma warning(push)
#pragma warning( disable : 4251 ) //disable needs to have dll-interface to be used by clients of class 'std::string'
#endif
#include <new>
#include <string>
namespace BALL
{
class String;
/** Exception
\ingroup Common
*/
namespace Exception
{
/** General exception class.
This class is intended as a base class for all other exceptions.
Each exception class should define a constructor taking a string
and an int as parameters. These two values are interpreted as the
current filename and line number and is usually printed in case of
an uncaught exception. To support this feature, each <b>throw</b>
directive should look as follows: \par
<tt><b>throw Exception::GeneralException</b>(__FILE__, __LINE__);</tt> \par
<tt>__FILE__</tt> and <tt>__LINE__</tt> are built-in preprocessor
macros that hold the desired information.
\par
BALL provides its own \link BALL::Exception::GlobalExceptionHandler::terminate terminate \endlink handler. This handler
extracts as much information as possible from the exception, prints
it to <tt>cerr</tt> and \link BALL::LogStream Log \endlink , and finally calls exits the program
cleanly (with exit code 1). This can be rather inconvenient for
debugging, since you are told where the exception was thrown, but
in general you do not know anything about the context. Therefore
<tt>terminate</tt> can also create a core dump. Using a debugger (e.g.
dbx or gdb) you can then create a stack traceback. To create a
core dump, you should set the environment variable <tt>
BALL_DUMP_CORE</tt> to any (non empty) value.
\ingroup Common
*/
class BALL_EXPORT GeneralException
: public std::exception
{
public:
/** @name Constructors and Destructors
*/
//@{
/// Default constructor
GeneralException();
/// Constructor
GeneralException(const char* file, int line);
/// Constructor
GeneralException
(const char* file, int line,
const String& name , const String& message);
/// Copy constructor
GeneralException(const GeneralException& exception);
/// Destructor
virtual ~GeneralException() throw();
//@}
/** @name Accessors
*/
//@{
/// Returns the name of the exception
const char* getName() const;
/// Returns the error message of the exception
const char* getMessage() const;
/// Modify the exception's error message
void setMessage(const std::string& message);
/// Returns the line number where it occured
int getLine() const;
/// Returns the file where it occured
const char* getFile() const;
//@}
protected:
const char* file_;
int line_;
std::string name_;
std::string message_;
};
/** Index underflow.
Throw this exception to indicate an index that was smaller than
allowed. The constructor has two additional arguments, the values
of which should be set to the index that caused the failure and the
smallest allowed value to simplify debugging.
@param index the value of the index causing the problem
@param size smallest value allowed for index
*/
class BALL_EXPORT IndexUnderflow
: public GeneralException
{
public:
IndexUnderflow(const char* file, int line, Index index = 0, Size size = 0);
protected:
Size size_;
Index index_;
};
/** Size underflow.
Throw this exception to indicate a size was smaller than allowed.
The constructor has an additional argument: the value of of the
requested size. This exception is thrown, if buffer sizes are
insufficient.
@param size the size causing the problem
*/
class BALL_EXPORT SizeUnderflow
: public GeneralException
{
public:
SizeUnderflow(const char* file, int line, Size size = 0);
protected:
Size size_;
};
/** Index overflow.
Throw this exception to indicate an index that was larger than
allowed. The constructor has two additional arguments, the values
of which should be set to the index that caused the failure and the
largest allowed value to simplify debugging.
@param index the value of the index causing the problem
@param size largest value allowed for index
*/
class BALL_EXPORT IndexOverflow
: public GeneralException
{
public:
IndexOverflow(const char* file, int line, Index index = 0, Size size = 0);
protected:
Size size_;
Index index_;
};
/** Invalid Argument
* Use this exception when a function is called with an invalid argument and no other exception applies.
*/
class BALL_EXPORT InvalidArgument
: public GeneralException
{
public:
InvalidArgument(const char* file, int line, const String& arg);
};
/** Invalid range.
Use this exception to indicate a general range problems.
*/
class BALL_EXPORT InvalidRange
: public GeneralException
{
public:
InvalidRange(const char* file, int line, float value);
};
/** Invalid Size
Throw this exception to indicate that a size was unexpected.
The constructor has an additional argument: the value of of the
requested size.
@param size the size causing the problem
*/
class BALL_EXPORT InvalidSize
: public GeneralException
{
public:
InvalidSize(const char* file, int line, Size size = 0);
protected:
Size size_;
};
/** Out of range.
Use this exception to indicate that a given value is out of a
defined range, i. e. not within the domain of a function.
*/
class BALL_EXPORT OutOfRange
: public GeneralException
{
public:
OutOfRange(const char* file, int line);
};
/** Invalid format.
This exception indicates a conversion problem when converting from
one type to another. It is thrown, if a conversion from ascii to
numeric formats or vice versa failed.
*/
class BALL_EXPORT InvalidFormat
: public GeneralException
{
public:
InvalidFormat(const char* file, int line, const String& s);
~InvalidFormat() throw();
protected:
std::string format_;
};
/** Illegal self operation.
Throw this excpetion to indicate an invalid operation on the object
itself. In general these operations are self assignments or related
methods.
*/
class BALL_EXPORT IllegalSelfOperation
: public GeneralException
{
public:
IllegalSelfOperation(const char* file, int line);
};
/** Null pointer argument is invalid.
Use this exception to indicate a failure due to an argument not
containing a pointer to a valid object, but a null pointer.
*/
class BALL_EXPORT NullPointer
: public GeneralException
{
public:
NullPointer(const char* file, int line);
};
/** Invalid iterator.
The iterator on which an operation should be performed was invalid.
*/
class BALL_EXPORT InvalidIterator
: public GeneralException
{
public:
InvalidIterator(const char* file, int line);
};
/** Incompatible iterator.
The iterators could not be assigned because they are bound to
different containers.
*/
class BALL_EXPORT IncompatibleIterators
: public GeneralException
{
public:
IncompatibleIterators(const char* file, int line);
};
/** Not implemented exception.
This exception should be thrown to indicate not yet inplemented
methods. If you take the time to use the detailed constructor
instead of the default constructor, identification of the concerned
source will get <b> much </b> easier!
*/
class BALL_EXPORT NotImplemented
: public GeneralException
{
public:
NotImplemented(const char* file, int line);
};
/** Illegal tree operation.
This exception is thrown to indicate that an illegal tree operation
i.e. node->setLeftChild(node) was requested.
*/
class BALL_EXPORT IllegalTreeOperation
: public GeneralException
{
public:
IllegalTreeOperation(const char* file, int line);
};
/** Out of memory.
Throw this exception to indicate that an allocation failed.
This exception is thrown in the BALL new handler.
@param size the number of bytes that should have been allocated
@see GlobalException::newHandler
*/
class BALL_EXPORT OutOfMemory
: public GeneralException, public std::bad_alloc
{
public:
OutOfMemory(const char* file, int line, Size size = 0);
virtual ~OutOfMemory()
throw();
protected:
Size size_;
};
/** Buffer overflow exception.
*/
class BALL_EXPORT BufferOverflow
: public GeneralException
{
public:
BufferOverflow(const char* file, int line);
};
/** Division by zero error.
*/
class BALL_EXPORT DivisionByZero
: public GeneralException
{
public:
DivisionByZero(const char* file, int line);
};
/** Out of grid error.
*/
class BALL_EXPORT OutOfGrid
: public GeneralException
{
public:
OutOfGrid(const char* file, int line);
};
/** File not found.
A given file could not be found.
*/
class BALL_EXPORT FileNotFound
: public GeneralException
{
public:
FileNotFound(const char* file, int line, const String& filename);
~FileNotFound()
throw();
String getFilename() const;
protected:
std::string filename_;
};
/** Invalid Position.
A given position in three dimensional is invalid.
*/
class BALL_EXPORT IllegalPosition
: public GeneralException
{
public:
IllegalPosition(const char* file, int line, float x, float y, float z);
};
/** Parse Error.
A given expression could not be parsed.
*/
class BALL_EXPORT ParseError
: public GeneralException
{
public:
///
ParseError(const char* file, int line, const String& expression,
const String& message);
};
/** Precondition failed.
A precondition (as defined by BALL_PRECONDITION_EXCEPTION) has failed.
*/
class BALL_EXPORT Precondition
: public GeneralException
{
public:
///
Precondition(const char* file, int line, const char* condition);
};
/** Postcondition failed.
A postcondition (as defined by BALL_POSTCONDITION_EXCEPTION) has failed.
*/
class BALL_EXPORT Postcondition
: public GeneralException
{
public:
///
Postcondition(const char* file, int line, const char* condition);
};
/// Exception to be thrown if an invalid option is given
class BALL_EXPORT InvalidOption: public Exception::GeneralException
{
public:
///
InvalidOption(const char* file, int line, String option);
};
/// Exception to be thrown if too many errors occur, e.g. in ForceField
class BALL_EXPORT TooManyErrors
: public Exception::GeneralException
{
public:
///
TooManyErrors(const char* file, int line);
};
/// Exception to be thrown if too many bonds for one atom
class BALL_EXPORT TooManyBonds
: public Exception::GeneralException
{
public:
///
TooManyBonds(const char* file, int line, const String& error);
};
/** CUDA Error
CUDA or any of its calls caused an error
*/
class BALL_EXPORT CUDAError
: public Exception::GeneralException
{
public:
CUDAError(const char* file, int line, const String& error);
};
/**
* RenderTarget error
* A buffer was requested from \link RenderTarget \endlink but could not be supplied
* for some reason at the given moment.
* Additional parameter <tt>reason</tt> gives the reason why the buffer could not be
* provided.
*/
class BALL_EXPORT NoBufferAvailable
: public Exception::GeneralException
{
public:
NoBufferAvailable(const char* file, int line, const String& reason);
};
/**
* BufferedRenderer error
* An unsuported format was requested from \link BufferedRenderer \endlink via
* <tt>setFrameBufferFormat</tt>.
*/
class BALL_EXPORT FormatUnsupported
: public Exception::GeneralException
{
public:
FormatUnsupported(const char* file, int line);
};
/** Class handling uncaught exception globally.
*/
class BALL_EXPORT GlobalExceptionHandler
{
public:
/** @name Constructors
*/
//@{
/** Default constructor.
This constructor installs the BALL specific handlers for
<tt>terminate</tt>, <tt>unexpected</tt>, and <tt>new_handler</tt>.
<tt>terminate</tt> or <tt>unexpected</tt> are called to abort
a program if an exception was not caught or a function
exits via an exception that is not allowed by its exception
specification. Both functions are replaced by a function of
GlobalExceptionHandler that tries to determine the
last exception thrown. This mechanism only works, if all
exceptions are defrived from \link GeneralException GeneralException \endlink . \par
The default <tt>new_handler</tt> is replaced by \link newHandler newHandler \endlink
and throws an exception of type \link OutOfMemory OutOfMemory \endlink instead of
<tt>bad_alloc</tt> (the default behaviour defined in the ANSI C++
standard).
*/
GlobalExceptionHandler();
//@}
/** @name Accessors
*/
//@{
/// Assign the name of the exception. This should agree with the class name.
static void setName(const String& name);
/// Set the error message
static void setMessage(const String& message);
/// Set the line number the exception was thrown. Should be set to __LINE__ in most cases.
static void setLine(int line);
/// The source file name where the exception was thrown
static void setFile(const String& file);
/// Set all exception attributes
static void set
(const String& file, int line,
const String& name, const String& message);
//@}
protected:
/// The BALL replacement for terminate
static void terminate();
/// The BALL new handler
static void newHandler() throw(Exception::OutOfMemory);
static std::string file_;
static int line_;
static std::string name_;
static std::string message_;
};
/** Global static instance of GlobalExceptionHandler
*/
BALL_EXPORT extern GlobalExceptionHandler globalHandler;
}
/** Output operator for exceptions.
All BALL exceptions can be printed to an arbitrary output stream.
Information written contains the exception class, the error message,
and the location (file, line number). The following code block
can thus be used to catch any BALL exceptions and convert them to
human readable information:
\verbatim
try
{
.... // some code which potentially throws an exception
}
catch (Exception::GeneralException& e)
{
Log.error() << "caught exception: " << e << std::endl;
}
\endverbatim
\ingroup Common
*/
BALL_EXPORT
std::ostream& operator << (std::ostream& os, const Exception::GeneralException& e);
} // namespace BALL
#ifdef BALL_COMPILER_MSVC
#pragma warning(pop)
#endif
#endif // BALL_COMMON_EXCEPTION_H
|