26 #ifndef ELEMENTSKERNEL_ELEMENTSKERNEL_EXCEPTION_H_
27 #define ELEMENTSKERNEL_ELEMENTSKERNEL_EXCEPTION_H_
34 #include <type_traits>
61 m_error_msg(message), m_exit_code{
e} {
70 m_error_msg(message), m_exit_code{
e} {
79 template <
typename ...Args>
80 explicit Exception(
const char* stringFormat, Args &&...args)
82 size_t len = snprintf(NULL, 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();
135 template<
typename... Args>
139 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>
164 template <
typename Ex,
typename T,
167 auto operator<<(Ex&& ex,
const T& message) -> decltype(std::forward<Ex>(ex)) {
168 ex.appendMessage(message);
169 return std::forward<Ex>(ex);
174 #endif // ELEMENTSKERNEL_ELEMENTSKERNEL_EXCEPTION_H_
ExitCodeHelper(const First &, const Rest &...rest)
ExitCode getCode(const T &)
Exception(const char *stringFormat, Args &&...args)
Constructs a new Exception with a message using format specifiers.
ExitCodeHelper(const Last &last)
ExitCode getCode(const T &t)
constexpr double e
The base of the natural logarithm .
void appendMessage(const T &message)
Appends in the end of the exception message the parameter.
defines the macros to be used for explicit export of the symbols
#define ELEMENTS_API
Dummy definitions for the backward compatibility mode.
Exception(const char *message, ExitCode e=ExitCode::NOT_OK)
Exception(ExitCode e=ExitCode::NOT_OK)
Exception(const std::string &message, ExitCode e=ExitCode::NOT_OK)
ExitCode
Strongly typed exit numbers.
ExitCode exitCode() const noexcept
define a list of standard exit codes for executables
ELEMENTS_API std::ostream & operator<<(std::ostream &, const Environment::Variable &)