Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
error_base.h
1#ifndef SOURCEMETA_CORE_ERROR_BASE_H_
2#define SOURCEMETA_CORE_ERROR_BASE_H_
3
4#ifndef SOURCEMETA_CORE_ERROR_EXPORT
5#include <sourcemeta/core/error_export.h>
6#endif
7
8#include <sourcemeta/core/text_static_string.h>
9
10#include <exception> // std::exception
11
12// Exporting symbols that depends on the standard C++ library is considered
13// safe.
14// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
15#if defined(_MSC_VER)
16#define SOURCEMETA_CORE_ERROR_WARNINGS_PUSH \
17 __pragma(warning(push)) __pragma(warning(disable : 4251 4275))
18#define SOURCEMETA_CORE_ERROR_WARNINGS_POP __pragma(warning(pop))
19#else
20#define SOURCEMETA_CORE_ERROR_WARNINGS_PUSH
21#define SOURCEMETA_CORE_ERROR_WARNINGS_POP
22#endif
23
24namespace sourcemeta::core {
25
26SOURCEMETA_CORE_ERROR_WARNINGS_PUSH
27
48class SOURCEMETA_CORE_ERROR_EXPORT Error : public std::exception {
49public:
50 [[nodiscard]] auto what() const noexcept -> const char * final;
51
78 [[nodiscard]] auto message() const noexcept -> StaticString {
79 return this->message_;
80 }
81
82protected:
84 explicit Error(const StaticString message) noexcept : message_{message} {}
85
86private:
87 StaticString message_;
88};
89
90SOURCEMETA_CORE_ERROR_WARNINGS_POP
91
92} // namespace sourcemeta::core
93
94#endif
auto message() const noexcept -> StaticString
Definition error_base.h:78
Error(const StaticString message) noexcept
Construct the error given its message.
Definition error_base.h:84
Definition text_static_string.h:20