|
3 | 3 | #include <fmt/core.h>
|
4 | 4 |
|
5 | 5 | #include <exception>
|
6 |
| -#include <memory> |
7 | 6 | #include <string>
|
8 | 7 | #include <utility>
|
9 | 8 |
|
10 | 9 | namespace error {
|
11 | 10 |
|
12 | 11 | /**
|
13 |
| - * @brief A class that represents error information. |
| 12 | + * @brief Represents error information. |
14 | 13 | */
|
15 |
| -class Error : public std::exception { |
16 |
| - private: |
| 14 | +struct Error : public std::exception { |
17 | 15 | std::string message; /**< The error message. */
|
18 | 16 |
|
19 |
| - public: |
20 | 17 | /**
|
21 |
| - * @brief Constructs a new error with the given format for the message. |
22 |
| - * @tparam T Variadic template parameter pack for format arguments. |
23 |
| - * @param fmt A format string for the message. |
24 |
| - * @param args Format arguments. |
| 18 | + * @brief Constructs a new error object with the given message. |
| 19 | + * @param msg An error message. |
25 | 20 | */
|
26 |
| - template <typename... T> |
27 |
| - Error(fmt::format_string<T...> fmt, T&&... args) |
28 |
| - : message(fmt::format(fmt, std::forward<T>(args)...)) {} |
| 21 | + Error(const std::string& msg); |
29 | 22 |
|
30 | 23 | /**
|
31 | 24 | * @brief Returns the explanatory string.
|
32 | 25 | * @return Pointer to a null-terminated string with explanatory information.
|
33 | 26 | */
|
34 | 27 | const char* what() const noexcept override;
|
35 |
| - |
36 |
| - /** |
37 |
| - * @brief Checks if the error message matches the given string. |
38 |
| - * @param str A string to be matched. |
39 |
| - * @return True if it matches, false otherwise. |
40 |
| - */ |
41 |
| - bool matches(const std::string& str) const noexcept; |
42 | 28 | };
|
43 | 29 |
|
44 | 30 | /**
|
45 |
| - * @brief Alias for a shared pointer to the `Error` class. |
46 |
| - */ |
47 |
| -using ErrorPtr = std::shared_ptr<Error>; |
48 |
| - |
49 |
| -/** |
50 |
| - * @brief Creates a new error pointer with the given format for the message. |
| 31 | + * @brief Creates a new error object with a formatted message. |
51 | 32 | * @tparam T Variadic template parameter pack for format arguments.
|
52 | 33 | * @param fmt A format string for the message.
|
53 | 34 | * @param args Format arguments.
|
54 |
| - * @return Shared pointer to a new error. |
| 35 | + * @return A new error object. |
55 | 36 | */
|
56 | 37 | template <typename... T>
|
57 |
| -ErrorPtr make(fmt::format_string<T...> fmt, T&&... args) { |
58 |
| - return std::make_shared<Error>(fmt, std::forward<T>(args)...); |
| 38 | +Error format(fmt::format_string<T...> fmt, T&&... args) { |
| 39 | + return Error(fmt::format(fmt, std::forward<T>(args)...)); |
59 | 40 | }
|
60 | 41 |
|
61 | 42 | } // namespace error
|
0 commit comments