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)...);
91 virtual ~Exception() noexcept = default;
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);
173 #endif // ELEMENTSKERNEL_ELEMENTSKERNEL_EXCEPTION_H_