#pragma once
#include "Types.hpp"
#include "libobsensor/h/Error.h"
#include <memory>
namespace ob {
class Error : public std::exception {
private:
ob_error *impl_;
explicit Error(ob_error *error) : impl_(error) {};
Error& operator=(const Error&) = default;
public:
static void handle(ob_error **error, bool throw_exception = true) {
if(!error || !*error) { return;
}
if(throw_exception) {
throw Error(*error);
}
else {
ob_delete_error(*error);
*error = nullptr;
}
}
~Error() override {
if(impl_) {
ob_delete_error(impl_);
impl_ = nullptr;
}
}
const char *what() const noexcept override {
return impl_->message;
}
OBExceptionType getExceptionType() const noexcept {
return impl_->exception_type;
}
const char *getFunction() const noexcept {
return impl_->function;
}
const char *getArgs() const noexcept {
return impl_->args;
}
const char *getMessage() const noexcept {
return impl_->message;
}
public:
const char *getName() const noexcept {
return impl_->function;
}
};
}