26 #ifndef ELEMENTSKERNEL_ELEMENTSKERNEL_EXCEPTION_H_
27 #define ELEMENTSKERNEL_ELEMENTSKERNEL_EXCEPTION_H_
34 #include <type_traits>
72 : m_error_msg(message), m_exit_code{
e} {}
80 template <
typename... Args>
82 std::size_t len = snprintf(
nullptr, 0, stringFormat, std::forward<Args>(args)...) + 1;
83 char* message =
new char[len];
84 snprintf(message, len, stringFormat, std::forward<Args>(args)...);
98 const
char* what() const noexcept
override {
99 return m_error_msg.c_str();
117 template <
typename T>
120 new_message << m_error_msg << message;
121 m_error_msg = new_message.
str();
134 template <
typename... Args>
138 template <
typename Last>
145 template <typename T, typename std::enable_if<std::is_same<T, ExitCode>::value>::type* =
nullptr>
150 template <typename T, typename std::enable_if<not std::is_same<T, ExitCode>::value>::type* =
nullptr>
157 template <
typename First,
typename... Rest>
163 template <
typename Ex,
typename T,
166 auto operator<<(Ex&& ex,
const T& message) -> decltype(std::forward<Ex>(ex)) {
167 ex.appendMessage(message);
168 return std::forward<Ex>(ex);
define a list of standard exit codes for executables
defines the macros to be used for explicit export of the symbols
Elements base exception class.
ExitCode exitCode() const noexcept
void appendMessage(const T &message)
Appends in the end of the exception message the parameter.
Exception(const std::string &message, ExitCode e=ExitCode::NOT_OK)
Exception(ExitCode e=ExitCode::NOT_OK)
virtual ~Exception() noexcept=default
Exception(const char *stringFormat, Args &&... args)
Constructs a new Exception with a message using format specifiers.
Exception(const char *message, ExitCode e=ExitCode::NOT_OK)
ExitCode
Strongly typed exit numbers.
#define ELEMENTS_API
Dummy definitions for the backward compatibility mode.
constexpr double e
The base of the natural logarithm .
auto operator<<(Ex &&ex, const T &message) -> decltype(std::forward< Ex >(ex))
@ NOT_OK
Generic unknown failure.
ExitCodeHelper(const First &, const Rest &... rest)
ExitCode getCode(const T &t)
ExitCode getCode(const T &)
ExitCodeHelper(const Last &last)