Elements 6.3.1
A C++ base framework for the Euclid Software.
Loading...
Searching...
No Matches
Exception.h
Go to the documentation of this file.
1
26#ifndef ELEMENTSKERNEL_ELEMENTSKERNEL_EXCEPTION_H_
27#define ELEMENTSKERNEL_ELEMENTSKERNEL_EXCEPTION_H_
28
29#include <exception> // for exception
30#include <string> // for string
31#include <type_traits> // for enable_if, is_same, remove_reference, is_base_of
32#include <utility> // for forward
33
34#include "ElementsKernel/Exit.h" // for ExitCode
35#include "ElementsKernel/Export.h" // for ELEMENTS_API
36
37namespace Elements {
38
45public:
51 explicit Exception(ExitCode e = ExitCode::NOT_OK);
52
62 explicit Exception(const char* message, ExitCode e = ExitCode::NOT_OK);
63
70 explicit Exception(const std::string& message, ExitCode e = ExitCode::NOT_OK);
71
78 template <typename... Args>
79 explicit Exception(const char* string_format, Args&&... args);
80
84 Exception(const Exception& rhs) = default;
85
89 virtual ~Exception() noexcept;
90
97 const char* what() const noexcept override;
98
103 ExitCode exitCode() const noexcept;
104
112 template <typename T>
113 void appendMessage(const T& message);
114
115protected:
119 std::string m_error_msg{};
120 const ExitCode m_exit_code{ExitCode::NOT_OK};
121
122private:
126 template <typename... Args>
127 struct ExitCodeHelper {};
128
129 // Specialization which handles the last argument
130 template <typename Last>
131 struct ExitCodeHelper<Last> {
132 explicit ExitCodeHelper(const Last& last);
134
135 private:
136 // This method is used if the T is an ExitCode object
137 template <typename T, typename std::enable_if<std::is_same<T, ExitCode>::value>::type* = nullptr>
138 ExitCode getCode(const T& t);
139
140 // This method is used when the T is not an ExitCode object
141 template <typename T, typename std::enable_if<not std::is_same<T, ExitCode>::value>::type* = nullptr>
142 ExitCode getCode(const T&);
143 };
144
145 // Specialization which handles two or more arguments
146 template <typename First, typename... Rest>
147 struct ExitCodeHelper<First, Rest...> : ExitCodeHelper<Rest...> {
148 explicit ExitCodeHelper(const First&, const Rest&... rest);
149 };
150};
151
152template <typename Ex, typename T,
153 typename = typename std::enable_if<
155ELEMENTS_API auto operator<<(Ex&& ex, const T& message) -> decltype(std::forward<Ex>(ex));
156
157} // namespace Elements
158
159#define ELEMENTSKERNEL_ELEMENTSKERNEL_EXCEPTION_IMPL_
160#include "ElementsKernel/_impl/Exception.tpp" // IWYU pragma: export
161#undef ELEMENTSKERNEL_ELEMENTSKERNEL_EXCEPTION_IMPL_
162
163#endif // ELEMENTSKERNEL_ELEMENTSKERNEL_EXCEPTION_H_
164
implementation of the templates declared in ElementsKernel/Exception.h
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.
Definition Exception.h:44
Exception(const char *string_format, Args &&... args)
Constructs a new Exception with a message using format specifiers.
virtual ~Exception() noexcept
Exception(const Exception &rhs)=default
T forward(T... args)
ExitCode
Strongly typed exit numbers.
Definition Exit.h:97
#define ELEMENTS_API
Dummy definitions for the backward compatibility mode.
Definition Export.h:74
ELEMENTS_API std::ostream & operator<<(std::ostream &, const Environment::Variable &)
STL namespace.
ExitCodeHelper(const First &, const Rest &... rest)