26 #ifndef ELEMENTSKERNEL_ELEMENTSKERNEL_EXCEPTION_H_
27 #define ELEMENTSKERNEL_ELEMENTSKERNEL_EXCEPTION_H_
34 #include <type_traits>
66 m_error_msg(message), m_exit_code{
e} {
75 m_error_msg(message), m_exit_code{
e} {
84 template <
typename ...Args>
85 explicit Exception(
const char* stringFormat, Args &&...args)
87 size_t len = snprintf(NULL, 0, stringFormat, std::forward<Args>(args)...)+1;
88 char* message =
new char[len];
89 snprintf(message, len, stringFormat, std::forward<Args>(args)...);
103 const
char * what() const noexcept
override {
104 return m_error_msg.c_str();
122 template <
typename T>
125 new_message << m_error_msg << message;
126 m_error_msg = new_message.
str();
140 template<
typename... Args>
144 template<
typename Last>
150 template<typename T, typename std::enable_if<std::is_same<T, ExitCode>::value>::type* =
nullptr>
155 template<typename T, typename std::enable_if<not std::is_same<T, ExitCode>::value>::type* =
nullptr>
162 template<
typename First,
typename... Rest>
169 template <
typename Ex,
typename T,
172 auto operator<<(Ex&& ex,
const T& message) -> decltype(std::forward<Ex>(ex)) {
173 ex.appendMessage(message);
174 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
Exception(const char *stringFormat, Args &&...args)
Constructs a new Exception with a message using format specifiers.
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 *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)