StormByte-Network 2.0.0
C++26 networking module of the StormByte suite
 
Loading...
Searching...
No Matches
exception.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Network.
5 *
6 * StormByte-Network original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Network source in this
20 * repository. They do not cover other StormByte modules or any third-party
21 * material shipped with this repository (including everything under
22 * thirdparty/, and in particular the bundled StormByte Buffer tree), which
23 * remains under its own license.
24 *
25 * Neither license grants any patent rights. Any patent licenses required
26 * to use this software or third-party components must be obtained separately
27 * from the patent holders.
28 *
29 * StormByte-Network is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU Lesser General Public License for more details.
33 *
34 * You should have received a copy of the GNU Lesser General Public License
35 * version 3 along with StormByte-Network. If not, see
36 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
37 *
38 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
39 */
40
41#pragma once
42
45
46#include <string>
47#include <string_view>
48#include <utility>
49
53namespace StormByte::Network {
59 public:
64 explicit Exception(std::string_view message):
65 StormByte::Exception(StormByte::Exception::Path{"Network"}, "{}", message) {}
66
71 explicit Exception(const StormByte::Safe::String& message):
72 Exception(static_cast<std::string_view>(message)) {}
73
80 template <typename... Args>
81 explicit Exception(std::format_string<Args...> fmt, Args&&... args):
82 StormByte::Exception(StormByte::Exception::Path{"Network"}, fmt,
83 std::forward<Args>(args)...) {}
84
92 template <typename... Args>
93 explicit Exception(StormByte::Exception::Path child, std::format_string<Args...> fmt,
94 Args&&... args):
96 StormByte::Exception::Path{std::string{"Network."}.append(child.text)},
97 fmt, std::forward<Args>(args)...) {}
98
104 explicit Exception(StormByte::Exception::Path child, std::string_view message):
106 StormByte::Exception::Path{std::string{"Network."}.append(child.text)}, "{}", message) {}
107
111 ~Exception() noexcept override;
112 };
113
119 public:
124 explicit ConnectionError(std::string_view message): Exception(StormByte::Exception::Path{"Connection"}, message) {}
125
132 template <typename... Args>
133 ConnectionError(std::format_string<Args...> fmt, Args&&... args):
134 Exception(StormByte::Exception::Path{"Connection"}, fmt, std::forward<Args>(args)...) {}
135
139 ~ConnectionError() noexcept override;
140
141 using Exception::Exception;
142 };
143
149 public:
154 explicit ConnectionClosed(std::string_view message):
155 Exception(StormByte::Exception::Path{"Connection"}, "Connection closed: {}", message) {}
156
163 template <typename... Args>
164 ConnectionClosed(std::format_string<Args...> fmt, Args&&... args):
165 Exception(StormByte::Exception::Path{"Connection"}, "Connection closed: {}",
166 std::format(fmt, std::forward<Args>(args)...)) {}
167
171 ~ConnectionClosed() noexcept override;
172
173 using Exception::Exception;
174 };
175
181 public:
186 explicit PacketError(std::string_view message):
187 Exception(StormByte::Exception::Path{"Transport.Packet"}, message) {}
188
195 template <typename... Args>
196 PacketError(std::format_string<Args...> fmt, Args&&... args):
197 Exception(StormByte::Exception::Path{"Transport.Packet"}, fmt, std::forward<Args>(args)...) {}
198
202 ~PacketError() noexcept override;
203
204 using Exception::Exception;
205 };
206
212 public:
217 explicit FrameError(std::string_view message):
218 Exception(StormByte::Exception::Path{"Transport.Frame"}, message) {}
219
226 template <typename... Args>
227 FrameError(std::format_string<Args...> fmt, Args&&... args):
228 Exception(StormByte::Exception::Path{"Transport.Frame"}, fmt, std::forward<Args>(args)...) {}
229
233 ~FrameError() noexcept override;
234
235 using Exception::Exception;
236 };
237}
Peer closed while waiting or transferring.
Definition exception.hxx:148
~ConnectionClosed() noexcept override
Destructor.
ConnectionClosed(std::format_string< Args... > fmt, Args &&... args)
Construct from a format string.
Definition exception.hxx:164
ConnectionClosed(std::string_view message)
Copy plain connection-closed text.
Definition exception.hxx:154
Connection or socket operation failed.
Definition exception.hxx:118
~ConnectionError() noexcept override
Destructor.
ConnectionError(std::format_string< Args... > fmt, Args &&... args)
Construct from a format string.
Definition exception.hxx:133
ConnectionError(std::string_view message)
Copy plain connection-error text.
Definition exception.hxx:124
Base exception for the Network module.
Definition exception.hxx:58
Exception(StormByte::Exception::Path child, std::format_string< Args... > fmt, Args &&... args)
Definition exception.hxx:93
~Exception() noexcept override
Destructor.
Exception(StormByte::Exception::Path child, std::string_view message)
Copy plain text under a Network child component.
Definition exception.hxx:104
Exception(const StormByte::Safe::String &message)
Copy Base-owned text under StormByte.Network.
Definition exception.hxx:71
Exception(std::format_string< Args... > fmt, Args &&... args)
Format an exception under StormByte.Network.
Definition exception.hxx:81
Exception(std::string_view message)
Copy plain exception text under StormByte.Network.
Definition exception.hxx:64
Transport frame error.
Definition exception.hxx:211
FrameError(std::format_string< Args... > fmt, Args &&... args)
Construct from a format string.
Definition exception.hxx:227
FrameError(std::string_view message)
Copy plain frame-error text.
Definition exception.hxx:217
~FrameError() noexcept override
Destructor.
Transport packet error.
Definition exception.hxx:180
PacketError(std::string_view message)
Copy plain packet-error text.
Definition exception.hxx:186
~PacketError() noexcept override
Destructor.
PacketError(std::format_string< Args... > fmt, Args &&... args)
Construct from a format string.
Definition exception.hxx:196
Network module of the StormByte suite.
Definition client.hxx:54
Root namespace of the StormByte suite.
STL namespace.
#define STORMBYTE_NETWORK_PUBLIC
Definition visibility.h:51