DiSMEC++
throw_error.h
Go to the documentation of this file.
1 // Copyright (c) 2021, Aalto University, developed by Erik Schultheis
2 // All rights reserved.
3 //
4 // SPDX-License-Identifier: MIT
5 
6 #ifndef DISMEC_THROW_ERROR_H
7 #define DISMEC_THROW_ERROR_H
8 
9 #include "spdlog/fmt/fmt.h"
10 
15 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
16 #define THROW_EXCEPTION(exception_type, ...) [&]() __attribute__((cold, noreturn)) { \
17  throw exception_type( fmt::format(__VA_ARGS__) ); \
18 }();
19 
23 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
24 #define ALWAYS_ASSERT_EQUAL(x, y, msg) \
25 { \
26 auto v1=(x); \
27 auto v2=(y); \
28 if(v1 != v2) { \
29  THROW_EXCEPTION(std::invalid_argument, msg, v1, v2); \
30 }}
31 #endif //DISMEC_THROW_ERROR_H