DFT-EFE
 
Loading...
Searching...
No Matches
Exceptions.h File Reference
#include <string>
#include <stdexcept>
#include <assert.h>
#include "Exceptions.t.cpp"
Include dependency graph for Exceptions.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  dftefe
 dealii includes
 
namespace  dftefe::utils
 

Macros

#define DFTEFE_Assert(expr)   assert(expr)
 provides an interface for exception handling. It two overrides on the assert(expr) function in C/C++ and two wrappers on std::exception. More...
 
#define DFTEFE_AssertWithMsg(expr, msg)   assert((expr) && (msg))
 

Typedefs

typedef std::logic_error dftefe::utils::LogicError
 
typedef std::invalid_argument dftefe::utils::InvalidArgument
 
typedef std::domain_error dftefe::utils::DomainError
 
typedef std::length_error dftefe::utils::LengthError
 
typedef std::out_of_range dftefe::utils::OutOfRangeError
 
typedef std::runtime_error dftefe::utils::RuntimeError
 
typedef std::overflow_error dftefe::utils::OverflowError
 
typedef std::underflow_error dftefe::utils::UnderflowError
 

Functions

void dftefe::utils::throwException (bool condition, std::string msg)
 
template<class T >
void dftefe::utils::throwException (bool condition, std::string msg="")
 

Macro Definition Documentation

◆ DFTEFE_Assert

#define DFTEFE_Assert (   expr)    assert(expr)

provides an interface for exception handling. It two overrides on the assert(expr) function in C/C++ and two wrappers on std::exception.

The overrides on assert(expr) are useful for debug mode testing. That is, you want the assert to be executed only in debug mode and not in release mode (i.e., if NDEBUG is defined). The two assert overrides are

  1. DFTEFE_Assert(expr): same as std::assert(expr). Throws an assert if expr is false
  2. DFTEFE_AssertWithMsg(expr,msg): same as above but takes an additional message in the form of string to display if expr is false.

It also provides two preprocessor flags, DFTEFE_DISABLE_ASSERT and DFTEFE_ENABLE_ASSERT, that you can set to override the NDEBUG flag in a particular source file. This is provided to allow selective enabling or disabling of Assert and AssertWithMsg without any relation to whether NDEBUG is defined or not (NDEBUG is typically defined globally for all files through compiler options). For example, if in a file you have #define DFTEFE_DISABLE_ASSERT #include "Exceptions.h" then it would disable all calls to Assert or AssertWithMsg in that file, regardless of whether NDEBUG is defined. Also, it has no bearing on std::assert (i.e., any calls to std::assert in that file will still be governed by NDEBUG). Similarly, if in a file you have #define DFTEFE_ENABLE_ASSERT #include "Exceptions.h" then it would enable all calls to Assert or AssertWithMsg in that file, regardless of whether NDEBUG is defined. Also, it has no bearning on std::assert (i.e., any calls to std::assert in that file will still be governed by NDEBUG)

It also provides two wrappers on std::exception and its derived classes (e.g., std::runtime_error, std::domain_error, etc.) The two wrappers are:

  1. dftefe::utils::throwException(expr,msg): a generic exception handler which throws an optional message (msg) if expr evaluates to false. It combines std::exception with an additional messgae. (Note: the std::exception has no easy way of taking in a message).
  2. dftefe::utils::throwException<T>(expr, msg): similar to the above, but takes a specific derived class of std::exception handler as a template parameter. The derived std::exception must have a constructor that takes in a string. For the ease of the user, we have typedef-ed some commonly used derived classes of std::exception. A user can use the typedefs as the template parameter instead. Available typedefs LogicError - std::logic_error InvalidArgument - std::invalid_argument DomainError - std::domain_error LengthError - std::length_error OutOfRangeError - std::out_of_range FutureError - std::future_error RuntimeError - std::runtime_error OverflowError - std::overflow_error UnderflowError - std::underflow_error

◆ DFTEFE_AssertWithMsg

#define DFTEFE_AssertWithMsg (   expr,
  msg 
)    assert((expr) && (msg))