tagval 0.2.0
Modern C++23 header-only library of tagged values (open/closed enumerations with metadata)
Loading...
Searching...
No Matches
error.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <stdexcept>
7#include <string>
8#include <string_view>
9
10namespace tagval {
11
13class TagValError : public std::runtime_error {
14public:
15 using std::runtime_error::runtime_error;
16};
17
20public:
21 using TagValError::TagValError;
22};
23
25struct ParseError {
26 std::string code;
27 std::string_view kind_id;
28
29 [[nodiscard]] std::string message() const {
30 std::string msg = "tagval: unknown code '";
31 msg += code;
32 msg += "' for kind '";
33 msg.append(kind_id);
34 msg += "'";
35 return msg;
36 }
37};
38
39} // namespace tagval
Common base exception. Catch this to handle any tagval-thrown error.
Definition error.hpp:13
Thrown by of() when a code is not present.
Definition error.hpp:19
Definition base.hpp:26
Returned via std::expected from try_of() when a code is not present.
Definition error.hpp:25
std::string code
The attempted code.
Definition error.hpp:26
std::string message() const
Definition error.hpp:29
std::string_view kind_id
The kind it was looked up in.
Definition error.hpp:27