smats
0.0.1
Satisfability Modulo Arithmetic Theories Symbols
Loading...
Searching...
No Matches
error.h
1
11
#pragma once
12
13
#include <stdexcept>
14
15
#include "smats/util/exception.h"
16
17
#ifdef NDEBUG
18
19
#define SMATS_ASSERT(condition, msg) ((void)0)
20
#define SMATS_ASSERT_FMT(condition, msg, ...) ((void)0)
21
#define SMATS_UNREACHABLE() ::std::terminate()
22
#define SMATS_RUNTIME_ERROR(msg) throw ::smats::SmatsException(msg)
23
#define SMATS_RUNTIME_ERROR_FMT(msg, ...) throw ::smats::SmatsException(msg)
24
#define SMATS_OUT_OF_RANGE_FMT(msg, ...) throw ::smats::SmatsOutOfRange(msg)
25
#define SMATS_INVALID_ARGUMENT(argument, actual) throw ::smats::SmatsInvalidArgument(argument)
26
#define SMATS_INVALID_ARGUMENT_EXPECTED(argument, actual, expected) throw ::smats::SmatsInvalidArgument(argument)
27
28
#else
29
30
#include <fmt/core.h>
31
32
#include "smats/util/logging.h"
33
34
#define SMATS_ASSERT(condition, message) \
35
do { \
36
if (!(condition)) { \
37
SMATS_CRITICAL_FMT("Assertion `{}` failed in {}:{}: {}", #condition, __FILE__, __LINE__, message); \
38
throw ::smats::SmatsAssertionError( \
39
fmt::format("Assertion `{}` failed in {}:{}: {}", #condition, __FILE__, __LINE__, message)); \
40
} \
41
} while (false)
42
43
#define SMATS_ASSERT_FMT(condition, message, ...) \
44
do { \
45
if (!(condition)) { \
46
SMATS_CRITICAL_FMT("Assertion `{}` failed in {}:{}", #condition, __FILE__, __LINE__); \
47
SMATS_CRITICAL_FMT(message, __VA_ARGS__); \
48
throw ::smats::SmatsAssertionError( \
49
fmt::format("Assertion `{}` failed in {}:{}", #condition, __FILE__, __LINE__) + "\n" + \
50
fmt::format(message, __VA_ARGS__)); \
51
} \
52
} while (false)
53
54
#define SMATS_UNREACHABLE() \
55
do { \
56
SMATS_CRITICAL_FMT("{}:{} Should not be reachable.", __FILE__, __LINE__); \
57
throw ::smats::SmatsUnreachable(fmt::format("{}:{} Should not be reachable.", __FILE__, __LINE__)); \
58
} while (false)
59
60
#define SMATS_RUNTIME_ERROR(msg) \
61
do { \
62
SMATS_CRITICAL(msg); \
63
throw ::smats::SmatsException(msg); \
64
} while (false)
65
66
#define SMATS_RUNTIME_ERROR_FMT(msg, ...) \
67
do { \
68
SMATS_CRITICAL_FMT(msg, __VA_ARGS__); \
69
throw ::smats::SmatsException(fmt::format(msg, __VA_ARGS__)); \
70
} while (false)
71
72
#define SMATS_OUT_OF_RANGE_FMT(msg, ...) \
73
do { \
74
SMATS_CRITICAL_FMT(msg, __VA_ARGS__); \
75
throw ::smats::SmatsOutOfRange(fmt::format(msg, __VA_ARGS__)); \
76
} while (false)
77
78
#define SMATS_INVALID_ARGUMENT(argument, actual) \
79
throw ::smats::SmatsInvalidArgument(fmt::format("Invalid argument for {}: {}", argument, actual))
80
81
#define SMATS_INVALID_ARGUMENT_EXPECTED(argument, actual, expected) \
82
throw ::smats::SmatsInvalidArgument( \
83
fmt::format("Invalid argument for {}: received '{}', expected '{}'", argument, actual, expected))
84
85
#define SMATS_NOT_IMPLEMENTED() throw ::smats::SmatsNotImplementedException()
86
87
#endif
// NDEBUG
smats
util
error.h
Generated by
1.11.0