Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
uri_error.h
1#ifndef SOURCEMETA_CORE_URI_ERROR_H_
2#define SOURCEMETA_CORE_URI_ERROR_H_
3
4#ifndef SOURCEMETA_CORE_URI_EXPORT
5#include <sourcemeta/core/uri_export.h>
6#endif
7
8#include <cstdint> // std::uint64_t
9#include <exception> // std::exception
10#include <string> // std::string
11#include <string_view> // std::string_view
12
13namespace sourcemeta::core {
14
15// Exporting symbols that depends on the standard C++ library is considered
16// safe.
17// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
18#if defined(_MSC_VER)
19#pragma warning(disable : 4251 4275)
20#endif
21
24class SOURCEMETA_CORE_URI_EXPORT URIParseError : public std::exception {
25public:
27 URIParseError(const std::uint64_t column) : column_{column} {}
28
29 [[nodiscard]] auto what() const noexcept -> const char * override {
30 return "The input is not a valid URI";
31 }
32
34 [[nodiscard]] auto column() const noexcept -> std::uint64_t {
35 return column_;
36 }
37
38private:
39 std::uint64_t column_;
40};
41
44class SOURCEMETA_CORE_URI_EXPORT URIError : public std::exception {
45public:
47 URIError(const char *message) : message_{message} {}
48 URIError(std::string message) = delete;
49 URIError(std::string &&message) = delete;
50 URIError(std::string_view message) = delete;
51
52 [[nodiscard]] auto what() const noexcept -> const char * override {
53 return this->message_;
54 }
55
56private:
57 const char *message_;
58};
59
60#if defined(_MSC_VER)
61#pragma warning(default : 4251 4275)
62#endif
63
64} // namespace sourcemeta::core
65
66#endif
URIError(const char *message)
Construct an error with the given message.
Definition uri_error.h:47
auto column() const noexcept -> std::uint64_t
Get the column number of the error.
Definition uri_error.h:34
URIParseError(const std::uint64_t column)
Construct an error from the column at which parsing failed.
Definition uri_error.h:27
Definition uri_error.h:44