Joedb 10.2.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
36 /// Indicates a bug in the code, thrown by @ref JOEDB_RELEASE_ASSERT
37 /// @ingroup error
39
40 /// Indicates a bug in the code, thrown by @ref JOEDB_DEBUG_ASSERT when NDEBUG not defined
41 /// @ingroup error
42 class Assertion_Failure: public std::logic_error
43 {
44 public:
45 explicit Assertion_Failure(const char *what_arg):
46 std::logic_error(what_arg)
47 {
48 }
49 };
50}
51
52#endif
Indicates a bug in the code, thrown by JOEDB_DEBUG_ASSERT when NDEBUG not defined.
Definition assert.h:43
Assertion_Failure(const char *what_arg)
Definition assert.h:45
std::string get_error_message(const char *condition, const char *full_file, const char *function, int line)
Definition assert.cpp:10