cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
server_exception.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <memory>
23
24#include <msgpack.hpp>
25
28#include "msgpack_rpc/impl/msgpack_rpc_export.h"
29
30namespace msgpack_rpc::clients {
31
38class MSGPACK_RPC_EXPORT ServerException : public MsgpackRPCException {
39public:
40 // Exceptions must be exported in libraries. If not exported, exceptions
41 // cannot be caught correctly.
42
50 msgpack::object object, std::shared_ptr<msgpack::zone> zone);
51
57 [[nodiscard]] const msgpack::object& object() const noexcept;
58
65 template <typename T>
66 [[nodiscard]] T error_as() const {
67 try {
68 return object().as<T>();
69 } catch (const msgpack::type_error&) {
71 StatusCode::TYPE_ERROR, "Invalid type of the error.");
72 }
73 }
74
79
84
90 ServerException& operator=(const ServerException&) noexcept;
91
97 ServerException& operator=(ServerException&&) noexcept;
98
100 ~ServerException() noexcept override;
101
102private:
104 std::shared_ptr<msgpack::zone> zone_;
105
107 msgpack::object object_;
108};
109
110} // namespace msgpack_rpc::clients
ServerException(const ServerException &) noexcept
Copy constructor.
ServerException(msgpack::object object, std::shared_ptr< msgpack::zone > zone)
Constructor.
ServerException(ServerException &&) noexcept
Move constructor.
msgpack::object object_
Object in msgpack library specifying the error.
std::shared_ptr< msgpack::zone > zone_
Zone in msgpack library.
const msgpack::object & object() const noexcept
Get the object in msgpack library.
Class of exceptions in cpp-msgpack-rpc library.
Definition of MsgpackRPCException class.
Namespace of clients.
Definition call_future.h:30
STL namespace.
Definition of StatusCode enumeration.