hexed 0.3.0
 
Loading...
Searching...
No Matches
assert.hpp File Reference

utilities for custom assertions More...

#include <stdexcept>
#include <vector>
#include <string>
#include <omp.h>
#include "config.hpp"

Classes

class  hexed::assert::Exception
 
class  hexed::assert::Numerical_exception
 represents a fatal problem in the numerics of the code (such as nonphysical values) More...
 
class  hexed::assert::User_error
 represents an exception which clearly results from a mistake made by the user More...
 

Namespaces

namespace  hexed
 Global namespace for all of the C++ API of Hexed.
 
namespace  hexed::assert
 utilities for custom assertions
 

Macros

#define HEXED_THROW(message, ...)
 Throws an exception with an informative error message.
 
#define HEXED_ASSERT(expression, message, ...)
 Assert something with an informative error message.
 

Functions

template<typename... format_args>
std::string hexed::format_str (int max_chars, std::string fstring, format_args... args)
 Standard string formatting.
 
template<typename except_t = std::runtime_error>
void hexed::assert::throw_critical (const char *message)
 

Detailed Description

utilities for custom assertions

Macro Definition Documentation

◆ HEXED_ASSERT

#define HEXED_ASSERT ( expression,
message,
... )
Value:
{ \
if (!(expression)) { \
HEXED_THROW(format_str(1000, \
"%s\n" \
" Assertion `%s` failed in `%s`.\n", \
std::string(message).c_str(), #expression, __FUNCTION__) \
__VA_OPT__(,) __VA_ARGS__ \
); \
} \
}

Assert something with an informative error message.

If expression is false, throws an exception with HEXED_THROW. message and an optional third argument are passed to HEXED_THROW.

◆ HEXED_THROW

#define HEXED_THROW ( message,
... )
Value:
{ \
assert::throw_critical<__VA_ARGS__>(format_str(1000, \
"%s\n" \
" At: line %d of `%s`\n" \
" In: %s", \
std::string(message).c_str(), __LINE__, __FILE__, __PRETTY_FUNCTION__).c_str()); \
}

Throws an exception with an informative error message.

Throws an exception with a message that includes message plus some additional info for debugging. Works inside single-threaded regions as well as OpenMP parallel regions. If desired, supply the type of exception as the third argument. Exception type must be constructible from a string. Defaults to std::runtime_error.