cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Toggle main menu visibility
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
26
#include "
msgpack_rpc/common/msgpack_rpc_exception.h
"
27
#include "
msgpack_rpc/common/status_code.h
"
28
#include "msgpack_rpc/impl/msgpack_rpc_export.h"
29
30
namespace
msgpack_rpc::clients
{
31
38
class
MSGPACK_RPC_EXPORT
ServerException
:
public
MsgpackRPCException
{
39
public
:
40
// Exceptions must be exported in libraries. If not exported, exceptions
41
// cannot be caught correctly.
42
49
ServerException
(
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&) {
70
throw
MsgpackRPCException
(
71
StatusCode::TYPE_ERROR,
"Invalid type of the error."
);
72
}
73
}
74
78
ServerException
(
const
ServerException
&)
noexcept
;
79
83
ServerException
(
ServerException
&&) noexcept;
84
90
ServerException
& operator=(const
ServerException
&) noexcept;
91
97
ServerException
& operator=(
ServerException
&&) noexcept;
98
100
~
ServerException
() noexcept override;
101
102
private:
104
std
::shared_ptr<msgpack::zone>
zone_
;
105
107
msgpack::
object
object_
;
108
};
109
110
}
// namespace msgpack_rpc::clients
msgpack_rpc::clients::ServerException::ServerException
ServerException(const ServerException &) noexcept
Copy constructor.
msgpack_rpc::clients::ServerException::ServerException
ServerException(msgpack::object object, std::shared_ptr< msgpack::zone > zone)
Constructor.
Definition
server_exception.cpp:31
msgpack_rpc::clients::ServerException::ServerException
ServerException(ServerException &&) noexcept
Move constructor.
msgpack_rpc::clients::ServerException::object_
msgpack::object object_
Object in msgpack library specifying the error.
Definition
server_exception.h:107
msgpack_rpc::clients::ServerException::zone_
std::shared_ptr< msgpack::zone > zone_
Zone in msgpack library.
Definition
server_exception.h:104
msgpack_rpc::clients::ServerException::error_as
T error_as() const
Get the error.
Definition
server_exception.h:66
msgpack_rpc::clients::ServerException::object
const msgpack::object & object() const noexcept
Get the object in msgpack library.
Definition
server_exception.cpp:39
msgpack_rpc::MsgpackRPCException
Class of exceptions in cpp-msgpack-rpc library.
Definition
msgpack_rpc_exception.h:35
msgpack_rpc_exception.h
Definition of MsgpackRPCException class.
msgpack_rpc::clients
Namespace of clients.
Definition
call_future.h:30
std
STL namespace.
status_code.h
Definition of StatusCode enumeration.
include
msgpack_rpc
clients
server_exception.h
Generated on
for cpp-msgpack-rpc by
1.18.0