OrbbecSDK 2.5.5
OrbbecSDK: Software-Development-Kit for Orbbec 3D Cameras
Loading...
Searching...
No Matches
Error.hpp
Go to the documentation of this file.
1// Copyright (c) Orbbec Inc. All Rights Reserved.
2// Licensed under the MIT License.
3
9#pragma once
10
11#include "Types.hpp"
12#include "libobsensor/h/Error.h"
13#include <memory>
14
15namespace ob {
16class Error : public std::exception {
17private:
18 ob_error *impl_;
19
27 explicit Error(ob_error *error) : impl_(error) {};
28
29 Error& operator=(const Error&) = default;
30
31public:
38 static void handle(ob_error **error, bool throw_exception = true) {
39 if(!error || !*error) { // no error
40 return;
41 }
42
43 if(throw_exception) {
44 throw Error(*error);
45 }
46 else {
47 ob_delete_error(*error);
48 *error = nullptr;
49 }
50 }
51
55 ~Error() override {
56 if(impl_) {
57 ob_delete_error(impl_);
58 impl_ = nullptr;
59 }
60 }
61
67 const char *what() const noexcept override {
68 return impl_->message;
69 }
70
78 return impl_->exception_type;
79 }
80
86 const char *getFunction() const noexcept {
87 return impl_->function;
88 }
89
95 const char *getArgs() const noexcept {
96 return impl_->args;
97 }
98
105 const char *getMessage() const noexcept {
106 return impl_->message;
107 }
108
109public:
110 // The following interfaces are deprecated and are retained here for compatibility purposes.
111 const char *getName() const noexcept {
112 return impl_->function;
113 }
114};
115} // namespace ob
116
Functions for handling errors, mainly used for obtaining error messages.
OB_EXPORT void ob_delete_error(ob_error *error)
Delete the error object.
OBExceptionType
The exception types in the SDK, through the exception type, you can easily determine the specific typ...
Definition ObTypes.h:99
const char * getName() const noexcept
Definition Error.hpp:111
const char * what() const noexcept override
Returns the error message of the exception.
Definition Error.hpp:67
const char * getMessage() const noexcept
Returns the error message of the exception.
Definition Error.hpp:105
~Error() override
Destroy the Error object.
Definition Error.hpp:55
const char * getFunction() const noexcept
Returns the name of the function where the exception occurred.
Definition Error.hpp:86
const char * getArgs() const noexcept
Returns the arguments of the function where the exception occurred.
Definition Error.hpp:95
OBExceptionType getExceptionType() const noexcept
Returns the exception type of the exception.
Definition Error.hpp:77
static void handle(ob_error **error, bool throw_exception=true)
A static function to handle the ob_error and throw an exception if needed.
Definition Error.hpp:38
Definition Context.hpp:19
The error class exposed by the SDK, users can get detailed error information according to the error.
Definition ObTypes.h:117