Joedb 10.0.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
assert.h
Go to the documentation of this file.
1#ifndef JOEDB_DEBUG_ASSERT
2
4
5#include <stdexcept>
6#include <string>
7
8#define JOEDB_CHECK(x,e) do\
9{\
10 if (!(x))\
11 throw e(joedb::get_error_message(#x, __FILE__, __func__, __LINE__).c_str());\
12} while(0)
13
14/// assertion tested in debug mode
15/// @ingroup error
16#if defined (NDEBUG) && !defined(JOEDB_FUZZING)
17#define JOEDB_DEBUG_ASSERT(x)
18#else
19#define JOEDB_DEBUG_ASSERT(x) JOEDB_CHECK(x, joedb::Assertion_Failure)
20#endif
21
22/// always-tested assertion (release and debug mode)
23/// @ingroup error
24#define JOEDB_RELEASE_ASSERT(x) JOEDB_CHECK(x, joedb::Release_Assertion_Failure)
25
26namespace joedb
27{
28 std::string get_error_message
29 (
30 const char *condition,
31 const char *file,
32 const char *function,
33 int line
34 );
35
37 /// Indicates a bug in the code, thrown by @ref JOEDB_DEBUG_ASSERT when NDEBUG not defined
38 /// @ingroup error
39 class Assertion_Failure: public std::logic_error
40 {
41 public:
42 explicit Assertion_Failure(const char *what_arg):
43 std::logic_error(what_arg)
44 {
45 }
46 };
47}
48
49#endif
Indicates a bug in the code, thrown by JOEDB_DEBUG_ASSERT when NDEBUG not defined.
Definition assert.h:40
Assertion_Failure(const char *what_arg)
Definition assert.h:42
Definition Blob.h:7
std::string get_error_message(const char *condition, const char *full_file, const char *function, int line)
Definition assert.cpp:10