Viam C++ SDK current
Loading...
Searching...
No Matches
exception.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <memory>
7#include <stdexcept>
8#include <string>
9#include <system_error>
10
11namespace grpc {
12
13class Status;
14
15} // namespace grpc
16
17namespace viam {
18namespace sdk {
19
21
26enum class ErrorCondition : uint8_t {
27 k_general = 0, // Default condition
28 k_connection = 1, // Issue during connection establishment
29 k_duplicate_registration = 2, // API or API/Model pair has already been registered
30 k_duplicate_resource = 3, // Resource has already been added
31 k_grpc = 4, // gRPC error from remote machine
32 k_not_supported = 5, // Behavior not supported by the SDK
33 k_resource_not_found = 6 // Resource does not exist
34};
35
36std::error_condition make_error_condition(ErrorCondition e);
37
41class Exception : public std::runtime_error {
42 public:
43 explicit Exception(ErrorCondition condition, const std::string& what);
44 explicit Exception(const std::string& what);
45
46 ~Exception() override = default;
47
48 const std::error_condition& condition() const noexcept;
49
50 private:
51 std::error_condition condition_;
52};
53
57class GRPCException : public Exception {
58 public:
59 explicit GRPCException(const grpc::Status* status);
60 ~GRPCException() override = default;
61
62 const grpc::Status* status() const noexcept;
63
64 private:
65 std::shared_ptr<grpc::Status> status_;
66};
67
68} // namespace sdk
69} // namespace viam
70
71namespace std {
72template <>
73struct is_error_condition_enum<viam::sdk::ErrorCondition> : true_type {};
74} // namespace std
Defines a set of a error conditions to be used in conjunction with Exception.
Defines an exception type for the SDK.
Definition exception.hpp:41
Defines an exception from a gRPC interaction.
Definition exception.hpp:57