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

utilities for custom assertions More...

#include "config.hpp"
#include <stdexcept>
#include <vector>
#include <string>
#include <omp.h>
#include "format_str.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...
 
class  hexed::assert::Not_implemented_error
 Indicates that the user invoked functionality which should be implemented in the future but isn't yet. More...
 
class  hexed::assert::Internal_error
 Indicates that a situation has been encountered which should not be possible, regardless of user input. More...
 
class  hexed::assert::Overflow_error
 Indicates an exception caused by some kind of fixed-size resource has been exhausted. 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 except_t = Internal_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(hexed::format_str( \
"%s\n" \
" Assertion `%s` failed in `%s`.", \
std::string(message).c_str(), #expression, __FUNCTION__) \
__VA_OPT__(,) __VA_ARGS__ \
); \
} \
}
std::string format_str(int max_chars, std::string fstring, format_args... args)
Standard string formatting.
Definition format_str.hpp:12

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.

Note
This macro expands to a block enclosed in {}, so it does not require a ; after it.

◆ HEXED_THROW

#define HEXED_THROW ( message,
... )
Value:
{ \
hexed::assert::throw_critical<__VA_ARGS__>(hexed::format_str( \
"%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.

Note
This macro expands to a block enclosed in {}, so it does not require a ; after it.