delpi  0.0.1
DElta-complete LP solver
Loading...
Searching...
No Matches
error.h
1
10#pragma once
11
12#include <fmt/core.h>
13
14#include <stdexcept>
15
16#include "delpi/util/exception.h"
17
18#ifdef NDEBUG
19
20#define DELPI_ASSERT(condition, msg) ((void)0)
21#define DELPI_ASSERT_FMT(condition, msg, ...) ((void)0)
22#define DELPI_UNREACHABLE() std::terminate()
23#define DELPI_NOT_IMPLEMENTED() throw ::delpi::DelpiNotImplementedException()
24#define DELPI_RUNTIME_ERROR(msg) throw ::delpi::DelpiException(msg)
25#define DELPI_RUNTIME_ERROR_FMT(msg, ...) throw ::delpi::DelpiException(fmt::format(msg, __VA_ARGS__))
26#define DELPI_OUT_OF_RANGE(msg) throw ::delpi::DelpiOutOfRangeException(msg)
27#define DELPI_OUT_OF_RANGE_FMT(msg, ...) throw ::delpi::DelpiOutOfRangeException(fmt::format(msg, __VA_ARGS__))
28#define DELPI_INVALID_ARGUMENT(argument, actual) \
29 throw ::delpi::DelpiInvalidArgumentException(fmt::format("Invalid argument for {}: {}", argument, actual))
30#define DELPI_INVALID_ARGUMENT_EXPECTED(argument, actual, expected) \
31 throw ::delpi::DelpiInvalidArgumentException( \
32 fmt::format("Invalid argument for {}: received '{}', expected '{}'", argument, actual, expected))
33
34#else
35
36#include "delpi/util/logging.h"
37
38#define DELPI_ASSERT(condition, message) \
39 do { \
40 if (!(condition)) { \
41 DELPI_CRITICAL_FMT("Assertion `{}` failed in {}:{}: {}", #condition, __FILE__, __LINE__, message); \
42 throw ::delpi::DelpiAssertionException( \
43 fmt::format("Assertion `{}` failed in {}:{}: {}", #condition, __FILE__, __LINE__, message)); \
44 } \
45 } while (false)
46
47#define DELPI_ASSERT_FMT(condition, message, ...) \
48 do { \
49 if (!(condition)) { \
50 DELPI_CRITICAL_FMT("Assertion `{}` failed in {}:{}\n" message, #condition, __FILE__, __LINE__, __VA_ARGS__); \
51 throw ::delpi::DelpiAssertionException( \
52 fmt::format("Assertion `{}` failed in {}:{}: " message, #condition, __FILE__, __LINE__, __VA_ARGS__)); \
53 } \
54 } while (false)
55
56#define DELPI_UNREACHABLE() \
57 do { \
58 DELPI_CRITICAL_FMT("{}:{} Should not be reachable.", __FILE__, __LINE__); \
59 throw ::delpi::DelpiUnreachableException(fmt::format("{}:{} Should not be reachable.", __FILE__, __LINE__)); \
60 } while (false)
61
62#define DELPI_NOT_IMPLEMENTED() \
63 do { \
64 DELPI_CRITICAL_FMT("{}:{} Not implemented.", __FILE__, __LINE__); \
65 throw ::delpi::DelpiNotImplementedException(fmt::format("{}:{} Not implemented.", __FILE__, __LINE__)); \
66 } while (false)
67
68#define DELPI_RUNTIME_ERROR(msg) \
69 do { \
70 DELPI_CRITICAL(msg); \
71 throw ::delpi::DelpiException(msg); \
72 } while (false)
73
74#define DELPI_RUNTIME_ERROR_FMT(msg, ...) \
75 do { \
76 DELPI_CRITICAL_FMT(msg, __VA_ARGS__); \
77 throw ::delpi::DelpiException(fmt::format(msg, __VA_ARGS__)); \
78 } while (false)
79
80#define DELPI_OUT_OF_RANGE(msg) \
81 do { \
82 DELPI_CRITICAL(msg); \
83 throw ::delpi::DelpiOutOfRangeException(msg); \
84 } while (false)
85
86#define DELPI_OUT_OF_RANGE_FMT(msg, ...) \
87 do { \
88 DELPI_CRITICAL_FMT(msg, __VA_ARGS__); \
89 throw ::delpi::DelpiOutOfRangeException(fmt::format(msg, __VA_ARGS__)); \
90 } while (false)
91
92#define DELPI_INVALID_ARGUMENT(argument, actual) \
93 throw ::delpi::DelpiInvalidArgumentException(fmt::format("Invalid argument for {}: {}", argument, actual))
94
95#define DELPI_INVALID_ARGUMENT_EXPECTED(argument, actual, expected) \
96 throw ::delpi::DelpiInvalidArgumentException( \
97 fmt::format("Invalid argument for {}: received '{}', expected '{}'", argument, actual, expected))
98
99#endif // NDEBUG