Hyper API for C++ 0.0.18825
Hyper client library for C++ applications
Loading...
Searching...
No Matches
HyperException.hpp
Go to the documentation of this file.
1
5#ifndef TABLEAU_HYPER_HYPEREXCEPTION_HPP
6#define TABLEAU_HYPER_HYPEREXCEPTION_HPP
7
8#include <hyperapi/impl/infra.hpp>
10#include <hyperapi/hyperapi.h>
11
12#include <cassert>
13#include <memory>
14#include <string>
15#include <system_error>
16
17namespace hyperapi {
18
24class ContextId final {
25 const uint32_t value_;
26
27 public:
28 constexpr explicit ContextId(uint32_t value) noexcept
29 : value_(value) {
30 }
31 constexpr uint32_t getValue() const noexcept { return value_; }
32};
33
34namespace internal {
35HyperException makeHyperException(const std::string&, const std::string&, ContextId);
36}
37
41class HyperException final : public std::exception {
42 public:
44 HyperException& operator=(const HyperException& other) noexcept;
46 HyperException(const HyperException& other) noexcept;
50 HyperException(HyperException&& other) = default;
51
55 const char* getMainMessage() const noexcept { return getStringField(HYPER_ERROR_FIELD_MESSAGE); }
56
60 const char* getHint() const noexcept { return getStringField(HYPER_ERROR_FIELD_HINT_MESSAGE); }
61
67 HYPER_DEPRECATED("Use getMainMessage() instead. This function will be removed in the future.")
68 const char*
69 getMessage() const noexcept {
70 return getMainMessage();
71 }
72
78 HYPER_DEPRECATED("Use getHint() instead. This function will be removed in the future.")
79 const char*
80 getHintMessage() const noexcept {
81 return getHint();
82 }
83
89 HYPER_DEPRECATED("Use getCause().has_value() instead. This function will be removed in the future.")
90 bool hasCause() const noexcept { return (getCauseHandle() != nullptr); }
91
96
100 ContextId getContextId() const noexcept { return ContextId(getUIntField(HYPER_ERROR_FIELD_CONTEXT_ID)); }
101
105 std::string toString() const;
106
110 const char* what() const noexcept override;
111
112 private:
120 explicit HyperException(hyper_error_t* error);
121
129 explicit HyperException(hyper_error_t* error, std::shared_ptr<const hyper_error_t> top_level_error);
130
136 const char* getStringField(hyper_error_field_key key) const noexcept;
137
143 int getIntField(hyper_error_field_key key) const noexcept;
144
150 uint32_t getUIntField(hyper_error_field_key key) const noexcept;
151
155 hyper_error_t* getCauseHandle() const noexcept;
156
158 std::shared_ptr<const hyper_error_t> error_;
159
161 mutable std::string stringRepresentation_;
162
163 friend const char* internal::getSqlState(const hyperapi::HyperException&);
164 friend const char* internal::getDetail(const hyperapi::HyperException&);
165 friend int internal::getErrorCode(const hyperapi::HyperException&);
166 friend int internal::getErrorCategory(const hyperapi::HyperException&);
167 friend hyper_error_source_t internal::getErrorSource(const hyperapi::HyperException&);
168 friend int internal::getErrorGrpcStatusCode(const hyperapi::HyperException&);
169 friend HyperException internal::makeHyperException(const std::string&, const std::string&, ContextId);
170 friend HyperException internal::makeHyperException(hyper_error_t*);
171 friend class HyperExceptionTest;
172};
173}
174
175#include <hyperapi/impl/HyperException.impl.hpp>
176
177#endif
Defines an exception object that is thrown on failure by the functions in the Hyper API C++ library.
HYPER_DEPRECATED("Use getMainMessage() instead. This function will be removed in the future.") const char *getMessage() const noexcept
Returns the message stored in the exception object, or "" if there is none.
HYPER_DEPRECATED("Use getCause().has_value() instead. This function will be removed in the future.") bool hasCause() const noexcept
Returns whether this error has an underlying cause stored.
HYPER_DEPRECATED("Use getHint() instead. This function will be removed in the future.") const char *getHintMessage() const noexcept
Returns the hint message stored in the exception object, or "" if there is none.
const char * getMainMessage() const noexcept
Returns the message stored in the exception object, or "" if there is none.
ContextId getContextId() const noexcept
Returns the context id.
optional< HyperException > getCause() const noexcept
Returns the cause stored in the exception object.
HyperException(const HyperException &other) noexcept
Copy constructor.
HyperException & operator=(const HyperException &other) noexcept
Copy assignment operator.
const char * what() const noexcept override
Returns a null terminated character sequence that may be used to identify the exception.
HyperException & operator=(HyperException &&other)=default
Move assignment operator.
const char * getHint() const noexcept
Returns the hint message stored in the exception object, or "" if there is none.
std::string toString() const
Returns a formatted string containing the message and hint of the error and all causes.
HyperException(HyperException &&other)=default
Move constructor.
Surrogate for C++17 std::optional
Definition optional.hpp:40
The primary namespace of the Hyper API for C++.
Definition ByteSpan.hpp:15