DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
Errors.hpp File Reference

Assertion / error-handling macros and supporting helper functions. More...

#include "Macros.hpp"
#include <iostream>
#include <cstdarg>
#include <sstream>
Include dependency graph for Errors.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  DNDS
 the host side operators are provided as implemented
 

Macros

#define DNDS_check_throw(expr)
 Runtime check active in both debug and release builds. Throws std::runtime_error if expr evaluates to false. Prefer this over DNDS_assert for user-input and API-contract checks.
 
#define DNDS_check_throw_info(expr, info)
 Same as DNDS_check_throw but attaches a user-supplied info message to the thrown std::runtime_error.
 
#define DNDS_assert(expr)
 Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + backtrace, then calls std::abort().
 
#define DNDS_assert_info(expr, info)
 Debug-only assertion with an extra std::string info message.
 
#define DNDS_assert_infof(expr, info, ...)
 Debug-only assertion with a printf-style format message.
 
#define DNDS_HD_assert(cond)   DNDS_assert(cond)
 Host-only expansion of DNDS_HD_assert (equivalent to DNDS_assert).
 
#define DNDS_HD_assert_infof(cond, info, ...)   DNDS_assert_infof(cond, info, ##__VA_ARGS__)
 Host-only expansion of DNDS_HD_assert_infof.
 
#define DNDS_DEVICE_CODE_GUARD_EIGEN_MALLOC   (void(0))
 

Functions

std::string DNDS::getTraceString ()
 Return a symbolicated stack trace for the calling thread.
 
void DNDS::assert_false (const char *expr, const char *file, int line)
 Low-level: print a red "DNDS_assertion failed" line and abort.
 
void DNDS::assert_false_info (const char *expr, const char *file, int line, const std::string &info)
 Variant of assert_false that prints an extra info string.
 
void DNDS::assert_false_infof (const char *expr, const char *file, int line, const char *info,...)
 printf-style variant of assert_false. Used by DNDS_assert_infof.
 
template<class TException = std::runtime_error>
void DNDS::assert_false_info_throw (const char *expr, const char *file, int line, const std::string &info)
 Throwing variant of assert_false_info. Used by DNDS_check_throw.
 

Detailed Description

Assertion / error-handling macros and supporting helper functions.

Overview

Three distinct families of checks are provided; choose based on how the failure should surface:

Macro Release behaviour Failure mode
DNDS_assert Compiled out (NDEBUG) std::abort()
DNDS_assert_info Compiled out (NDEBUG) std::abort() + message
DNDS_assert_infof Compiled out (NDEBUG) std::abort() + fmtprintf
DNDS_check_throw Always active throw std::runtime_error
DNDS_check_throw_info Always active throw + message
DNDS_HD_assert Compiled out in NDEBUG host: abort, device: trap

Prefer DNDS_assert for internal invariants that are expensive to check or cannot fail in correct code; use DNDS_check_throw for user-input / runtime validation that must remain active in release builds.

The device variants (DNDS_HD_*) expand to host asserts on the host and to atomic-guarded PTX trap on CUDA devices so only one thread prints.

Definition in file Errors.hpp.

Macro Definition Documentation

◆ DNDS_assert

#define DNDS_assert (   expr)
Value:
((static_cast<bool>(expr)) \
? void(0) \
: ::DNDS::assert_false(#expr, __FILE__, __LINE__))
void assert_false(const char *expr, const char *file, int line)
Low-level: print a red "DNDS_assertion failed" line and abort.
Definition Errors.hpp:40

Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + backtrace, then calls std::abort().

Definition at line 108 of file Errors.hpp.

◆ DNDS_assert_info

#define DNDS_assert_info (   expr,
  info 
)
Value:
((static_cast<bool>(expr)) \
? void(0) \
: ::DNDS::assert_false_info(#expr, __FILE__, __LINE__, info))
void assert_false_info(const char *expr, const char *file, int line, const std::string &info)
Variant of assert_false that prints an extra info string.
Definition Errors.hpp:48

Debug-only assertion with an extra std::string info message.

Definition at line 113 of file Errors.hpp.

◆ DNDS_assert_infof

#define DNDS_assert_infof (   expr,
  info,
  ... 
)
Value:
((static_cast<bool>(expr)) \
? void(0) \
: ::DNDS::assert_false_infof(#expr, __FILE__, __LINE__, info, ##__VA_ARGS__))
void assert_false_infof(const char *expr, const char *file, int line, const char *info,...)
printf-style variant of assert_false. Used by DNDS_assert_infof.
Definition Errors.hpp:57

Debug-only assertion with a printf-style format message.

Definition at line 118 of file Errors.hpp.

◆ DNDS_check_throw

#define DNDS_check_throw (   expr)
Value:
((static_cast<bool>(expr)) \
? void(0) \
: ::DNDS::assert_false_info_throw(#expr, __FILE__, __LINE__, ""))
void assert_false_info_throw(const char *expr, const char *file, int line, const std::string &info)
Throwing variant of assert_false_info. Used by DNDS_check_throw.
Definition Errors.hpp:76

Runtime check active in both debug and release builds. Throws std::runtime_error if expr evaluates to false. Prefer this over DNDS_assert for user-input and API-contract checks.

Definition at line 89 of file Errors.hpp.

◆ DNDS_check_throw_info

#define DNDS_check_throw_info (   expr,
  info 
)
Value:
((static_cast<bool>(expr)) \
? void(0) \
: ::DNDS::assert_false_info_throw(#expr, __FILE__, __LINE__, info))

Same as DNDS_check_throw but attaches a user-supplied info message to the thrown std::runtime_error.

Definition at line 96 of file Errors.hpp.

◆ DNDS_DEVICE_CODE_GUARD_EIGEN_MALLOC

#define DNDS_DEVICE_CODE_GUARD_EIGEN_MALLOC   (void(0))

Definition at line 207 of file Errors.hpp.

◆ DNDS_HD_assert

#define DNDS_HD_assert (   cond)    DNDS_assert(cond)

Host-only expansion of DNDS_HD_assert (equivalent to DNDS_assert).

Definition at line 189 of file Errors.hpp.

◆ DNDS_HD_assert_infof

#define DNDS_HD_assert_infof (   cond,
  info,
  ... 
)    DNDS_assert_infof(cond, info, ##__VA_ARGS__)

Host-only expansion of DNDS_HD_assert_infof.

Definition at line 191 of file Errors.hpp.