dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
exception.h
1
11#pragma once
12
13#include <fmt/core.h>
14
15#include <stdexcept>
16
17#ifdef NDEBUG
18
19#define DLINEAR_ASSERT(condition, msg) ((void)0)
20#define DLINEAR_ASSERT_FMT(condition, msg, ...) ((void)0)
21#define DLINEAR_UNREACHABLE() std::terminate()
22#define DLINEAR_RUNTIME_ERROR(msg) throw std::runtime_error(msg)
23#define DLINEAR_RUNTIME_ERROR_FMT(msg, ...) throw std::runtime_error(msg)
24#define DLINEAR_OUT_OF_RANGE(msg) throw std::out_of_range(msg)
25#define DLINEAR_OUT_OF_RANGE_FMT(msg, ...) throw std::out_of_range(msg)
26#define DLINEAR_INVALID_ARGUMENT(argument, actual) throw std::runtime_error(argument)
27#define DLINEAR_INVALID_ARGUMENT_EXPECTED(argument, actual, expected) \
28 throw std::invalid_argument( \
29 fmt::format("Invalid argument for {}: received '{}', expected '{}'", argument, actual, expected))
30
31#else
32
33#include "dlinear/util/logging.h"
34
35#define DLINEAR_ASSERT(condition, message) \
36 do { \
37 if (!(condition)) { \
38 DLINEAR_CRITICAL_FMT("Assertion `{}` failed in {}:{}: {}", #condition, __FILE__, __LINE__, message); \
39 std::terminate(); \
40 } \
41 } while (false)
42
43#define DLINEAR_ASSERT_FMT(condition, message, ...) \
44 do { \
45 if (!(condition)) { \
46 DLINEAR_CRITICAL_FMT("Assertion `{}` failed in {}:{}", #condition, __FILE__, __LINE__); \
47 DLINEAR_CRITICAL_FMT(message, __VA_ARGS__); \
48 std::terminate(); \
49 } \
50 } while (false)
51
52#define DLINEAR_UNREACHABLE() \
53 do { \
54 DLINEAR_CRITICAL_FMT("{}:{} Should not be reachable.", __FILE__, __LINE__); \
55 std::terminate(); \
56 } while (false)
57
58#define DLINEAR_RUNTIME_ERROR(msg) \
59 do { \
60 DLINEAR_CRITICAL(msg); \
61 throw std::runtime_error(msg); \
62 } while (false)
63
64#define DLINEAR_RUNTIME_ERROR_FMT(msg, ...) \
65 do { \
66 DLINEAR_CRITICAL_FMT(msg, __VA_ARGS__); \
67 throw std::runtime_error(fmt::format(msg, __VA_ARGS__)); \
68 } while (false)
69
70#define DLINEAR_OUT_OF_RANGE(msg) \
71 do { \
72 DLINEAR_CRITICAL(msg); \
73 throw std::out_of_range(msg); \
74 } while (false)
75
76#define DLINEAR_OUT_OF_RANGE_FMT(msg, ...) \
77 do { \
78 DLINEAR_CRITICAL_FMT(msg, __VA_ARGS__); \
79 throw std::out_of_range(fmt::format(msg, __VA_ARGS__)); \
80 } while (false)
81
82#define DLINEAR_INVALID_ARGUMENT(argument, actual) \
83 throw std::invalid_argument(fmt::format("Invalid argument for {}: {}", argument, actual))
84
85#define DLINEAR_INVALID_ARGUMENT_EXPECTED(argument, actual, expected) \
86 throw std::invalid_argument( \
87 fmt::format("Invalid argument for {}: received '{}', expected '{}'", argument, actual, expected))
88
89#endif // NDEBUG