Hyper API for C++ 0.0.24081
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
16namespace hyperapi {
17
23class ContextId final {
24 const uint32_t value_;
25
26 public:
27 constexpr explicit ContextId(uint32_t value) noexcept
28 : value_(value) {
29 }
30 constexpr uint32_t getValue() const noexcept { return value_; }
31};
32
33namespace internal {
34HyperException makeHyperException(const std::string&, const std::string&, ContextId);
35}
36
40class HyperException final : public std::exception {
41 public:
43 HyperException& operator=(const HyperException& other) noexcept;
45 HyperException(const HyperException& other) noexcept;
49 HyperException(HyperException&& other) = default;
50
54 const char* getMainMessage() const noexcept { return getStringField(HYPER_ERROR_FIELD_MESSAGE); }
55
59 const char* getHint() const noexcept { return getStringField(HYPER_ERROR_FIELD_HINT_MESSAGE); }
60
66 HYPER_DEPRECATED("Use getMainMessage() instead. This function will be removed in the future.")
67 const char*
68 getMessage() const noexcept {
69 return getMainMessage();
70 }
71
77 HYPER_DEPRECATED("Use getHint() instead. This function will be removed in the future.")
78 const char*
79 getHintMessage() const noexcept {
80 return getHint();
81 }
82
88 HYPER_DEPRECATED("Use getCause().has_value() instead. This function will be removed in the future.")
89 bool hasCause() const noexcept { return (getCauseHandle() != nullptr); }
90
95
99 ContextId getContextId() const noexcept { return ContextId(getUIntField(HYPER_ERROR_FIELD_CONTEXT_ID)); }
100
104 std::string toString() const;
105
109 const char* what() const noexcept override;
110
111 private:
119 explicit HyperException(hyper_error_t* error);
120
128 explicit HyperException(hyper_error_t* error, std::shared_ptr<const hyper_error_t> top_level_error);
129
135 const char* getStringField(hyper_error_field_key key) const noexcept;
136
142 int getIntField(hyper_error_field_key key) const noexcept;
143
149 uint32_t getUIntField(hyper_error_field_key key) const noexcept;
150
154 hyper_error_t* getCauseHandle() const noexcept;
155
157 std::shared_ptr<const hyper_error_t> error_;
158
160 mutable std::string stringRepresentation_;
161
162 friend const char* internal::getSqlState(const hyperapi::HyperException&);
163 friend const char* internal::getDetail(const hyperapi::HyperException&);
164 friend int internal::getErrorCode(const hyperapi::HyperException&);
165 friend int internal::getErrorCategory(const hyperapi::HyperException&);
166 friend hyper_error_source_t internal::getErrorSource(const hyperapi::HyperException&);
167 friend int internal::getErrorGrpcStatusCode(const hyperapi::HyperException&);
168 friend HyperException internal::makeHyperException(const std::string&, const std::string&, ContextId);
169 friend HyperException internal::makeHyperException(hyper_error_t*);
170 friend class HyperExceptionTest;
171};
172}
173
174#include <hyperapi/impl/HyperException.impl.hpp>
175
176#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:14