-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorCode.hpp
More file actions
37 lines (30 loc) · 928 Bytes
/
ErrorCode.hpp
File metadata and controls
37 lines (30 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#if !defined(ELUCIDATE__UTIL__ERRORCODE_HPP)
#define ELUCIDATE__UTIL__ERRORCODE_HPP
#include "TracedTerminate.hpp"
#include "Trace.hpp"
#include <optional>
namespace Elucidate::Util {
/** @brief check a C-style error code, terminating on error */
template< typename T, typename U >
void checkReturnAndThrow(T const& goodValue, U const& actual, const char* error,
std::optional< T > const& warnValue = std::optional< T >()) {
if (goodValue != actual) {
if (warnValue && (warnValue.value() == actual)) {
LOG_WARN << "received " << warnValue.value() << " for "
<< error;
} else {
LOG_ERROR << actual;
TRACED_TERMINATE(error);
}
}
}
/** @brief check a C-style error code, terminating on error */
template< typename T, typename U >
void checkForBadReturn(T const& badValue, U const& actual, const char* error) {
if (badValue == actual) {
LOG_ERROR << actual;
TRACED_TERMINATE(error);
}
}
}
#endif