5#ifndef TABLEAU_HYPER_HYPEREXCEPTION_HPP
6#define TABLEAU_HYPER_HYPEREXCEPTION_HPP
8#include <hyperapi/impl/infra.hpp>
10#include <hyperapi/hyperapi.h>
15#include <system_error>
25 const uint32_t value_;
28 constexpr explicit ContextId(uint32_t value) noexcept
31 constexpr uint32_t getValue()
const noexcept {
return value_; }
55 const char*
getMainMessage() const noexcept {
return getStringField(HYPER_ERROR_FIELD_MESSAGE); }
60 const char*
getHint() const noexcept {
return getStringField(HYPER_ERROR_FIELD_HINT_MESSAGE); }
67 HYPER_DEPRECATED(
"Use getMainMessage() instead. This function will be removed in the future.")
69 getMessage() const noexcept {
78 HYPER_DEPRECATED(
"Use getHint() instead. This function will be removed in the future.")
80 getHintMessage() const noexcept {
89 HYPER_DEPRECATED(
"Use getCause().has_value() instead. This function will be removed in the future.")
90 bool hasCause() const noexcept {
return (getCauseHandle() !=
nullptr); }
110 const char*
what() const noexcept override;
129 explicit
HyperException(hyper_error_t* error, std::shared_ptr<const hyper_error_t> top_level_error);
136 const
char* getStringField(hyper_error_field_key key) const noexcept;
143 int getIntField(hyper_error_field_key key) const noexcept;
150 uint32_t getUIntField(hyper_error_field_key key) const noexcept;
155 hyper_error_t* getCauseHandle() const noexcept;
158 std::shared_ptr<const hyper_error_t> error_;
161 mutable std::
string stringRepresentation_;
170 friend
HyperException internal::makeHyperException(hyper_error_t*);
171 friend class HyperExceptionTest;
175#include <hyperapi/impl/HyperException.impl.hpp>
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
The primary namespace of the Hyper API for C++.