Skip to content

Commit

Permalink
use shared_ptr and make dtors override = default
Browse files Browse the repository at this point in the history
  • Loading branch information
lia-viam committed Jan 7, 2025
1 parent 546d782 commit 1b67b11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 1 addition & 5 deletions src/viam/sdk/common/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Exception::Exception(ErrorCondition condition, const std::string& what)

Exception::Exception(const std::string& what) : Exception(ErrorCondition::k_general, what) {};

Exception::~Exception() = default;

const std::error_condition& Exception::condition() const noexcept {
return condition_;
};
Expand Down Expand Up @@ -49,9 +47,7 @@ std::error_condition make_error_condition(ErrorCondition e) {

GRPCException::GRPCException(const grpc::Status* status)
: Exception(ErrorCondition::k_grpc, status->error_message()),
status_(std::make_unique<grpc::Status>(*status)) {}

GRPCException::~GRPCException() = default;
status_(std::make_shared<grpc::Status>(*status)) {}

const grpc::Status* GRPCException::status() const noexcept {
return status_.get();
Expand Down
7 changes: 4 additions & 3 deletions src/viam/sdk/common/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class Exception : public std::runtime_error {
public:
explicit Exception(ErrorCondition condition, const std::string& what);
explicit Exception(const std::string& what);
virtual ~Exception();

~Exception() override = default;

const std::error_condition& condition() const noexcept;

Expand All @@ -56,12 +57,12 @@ class Exception : public std::runtime_error {
class GRPCException : public Exception {
public:
explicit GRPCException(const grpc::Status* status);
~GRPCException();
~GRPCException() override = default;

const grpc::Status* status() const noexcept;

private:
std::unique_ptr<grpc::Status> status_;
std::shared_ptr<grpc::Status> status_;
};

} // namespace sdk
Expand Down

0 comments on commit 1b67b11

Please sign in to comment.