src/Base/Exception.hpp file

Exception class declaration.

Contents

Exception class declaration. The basic functionality provided by the Exception class is to facilitate printing out a message, together with the location of the exception (file, line, funcion name), as well as a call trace if available, when an exception is thrown. This file also defines three macros, Throw, Assert, and ErrChk, that help simplifying client code throwing exceptions.

Namespaces

namespace tk
Toolkit declarations and definitions for general purpose utilities.

Classes

class tk::Exception
Basic exception class for producing file:func:line info + call trace.

Defines

#define Throw(...)
Throw macro that always throws an exception.
#define Assert(expr, ...)
Assert macro that only throws an exception if expr fails.
#define ErrChk(expr, ...)
ErrChk macro that only throws an exception if expr fails.

Define documentation

#define Throw(...)

Throw macro that always throws an exception.

Throw Exception with arguments passed in. Add source filename, function name, and line number where exception occurred. This macro facilitates a throw of Exception that is somehwat cleaner at the point of invocation than a direct throw of Exception, as it hides the file:func:line arguments. Whenever is possible, it should be used via the Assert and ErrChk macros defined below.

#define Assert(expr, ...)

Assert macro that only throws an exception if expr fails.

If NDEBUG is defined (e.g. cmake's RELEASE or OPTIMIZED mode), do nothing, expr is not evaluated. If NDEBUG is not defined, evaluate expr. If expr is true, do nothing. If expr is false, throw Exception with arguments passed in. The behavior is similar to libc's assert macro, but throwing an Exception instead will also generate a nice call-trace and will attempt to free memory. This macro should be used to detect programmer errors.

#define ErrChk(expr, ...)

ErrChk macro that only throws an exception if expr fails.

The behavior of this macro is the same whether NDEBUG is defined or not: expr is always evaluated. If expr is true, do nothing. If expr is false, throw Exception with arguments passed in. This macro should be used to detect user or runtime errors.