StormByte-Network 4.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
43#include <StormByte/exception.hxx>
45#include <StormByte/safe/string.hxx>
46
47#include <string_view>
48#include <utility>
49
54namespace StormByte {
59 namespace Network {
76 public:
81 struct Path {
82 std::string_view segments;
83
88 explicit constexpr Path(std::string_view segments = {}) noexcept: segments(segments) {}
89 };
90
97 template <typename... Args>
98 requires (sizeof...(Args) >= 1)
99 explicit Exception(std::string_view pattern, Args&&... args)
100 : StormByte::Exception(StormByte::Exception::Path{"Network"}, pattern, std::forward<Args>(args)...) {}
101
106 explicit Exception(std::string_view message);
107
115 template <typename... Args>
116 requires (sizeof...(Args) >= 1)
117 explicit Exception(Path path, std::string_view pattern, Args&&... args)
118 : Exception(path, static_cast<std::string_view>(StormByte::Safe::String::ReplaceToken(pattern, std::forward<Args>(args)...))) {}
119
125 explicit Exception(Path path, std::string_view message);
126
131 Exception(const Exception& other);
132
137 Exception(Exception&& other) noexcept;
138
145
151 Exception& operator=(Exception&& other) noexcept;
152
156 ~Exception() noexcept override;
157 };
158
164 public:
171 template <typename... Args>
172 requires (sizeof...(Args) >= 1)
173 explicit ConnectionError(std::string_view pattern, Args&&... args)
174 : Exception(Path{"Connection"}, pattern, std::forward<Args>(args)...) {}
175
180 explicit ConnectionError(std::string_view message)
181 : Exception(Path{"Connection"}, message) {}
182
190 template <typename... Args>
191 requires (sizeof...(Args) >= 1)
192 explicit ConnectionError(Path path, std::string_view pattern, Args&&... args)
193 : Exception(path, pattern, std::forward<Args>(args)...) {}
194
200 explicit ConnectionError(Path path, std::string_view message)
201 : Exception(path, message) {}
202
208
214
218 ~ConnectionError() noexcept override;
219
225 ConnectionError& operator=(const ConnectionError& other);
226
232 ConnectionError& operator=(ConnectionError&& other) noexcept;
233 };
234
243 public:
250 template <typename... Args>
251 requires (sizeof...(Args) >= 1)
252 explicit ConnectionClosed(std::string_view pattern, Args&&... args)
253 : Exception(Path{"Connection"}, "Connection closed: {}",
254 static_cast<std::string_view>(StormByte::Safe::String::ReplaceToken(pattern, std::forward<Args>(args)...))) {}
255
260 explicit ConnectionClosed(std::string_view message)
261 : Exception(Path{"Connection"}, "Connection closed: {}", message) {}
262
270 template <typename... Args>
271 requires (sizeof...(Args) >= 1)
272 explicit ConnectionClosed(Path path, std::string_view pattern, Args&&... args)
273 : Exception(path, pattern, std::forward<Args>(args)...) {}
274
280 explicit ConnectionClosed(Path path, std::string_view message)
281 : Exception(path, message) {}
282
288
294
298 ~ConnectionClosed() noexcept override;
299
305 ConnectionClosed& operator=(const ConnectionClosed& other);
306
312 ConnectionClosed& operator=(ConnectionClosed&& other) noexcept;
313 };
314
320 public:
327 template <typename... Args>
328 requires (sizeof...(Args) >= 1)
329 explicit PacketError(std::string_view pattern, Args&&... args)
330 : Exception(Path{"Transport.Packet"}, pattern, std::forward<Args>(args)...) {}
331
336 explicit PacketError(std::string_view message)
337 : Exception(Path{"Transport.Packet"}, message) {}
338
346 template <typename... Args>
347 requires (sizeof...(Args) >= 1)
348 explicit PacketError(Path path, std::string_view pattern, Args&&... args)
349 : Exception(path, pattern, std::forward<Args>(args)...) {}
350
356 explicit PacketError(Path path, std::string_view message)
357 : Exception(path, message) {}
358
364
369 PacketError(PacketError&& other) noexcept;
370
374 ~PacketError() noexcept override;
375
381 PacketError& operator=(const PacketError& other);
382
388 PacketError& operator=(PacketError&& other) noexcept;
389 };
390
396 public:
403 template <typename... Args>
404 requires (sizeof...(Args) >= 1)
405 explicit FrameError(std::string_view pattern, Args&&... args)
406 : Exception(Path{"Transport.Frame"}, pattern, std::forward<Args>(args)...) {}
407
412 explicit FrameError(std::string_view message)
413 : Exception(Path{"Transport.Frame"}, message) {}
414
422 template <typename... Args>
423 requires (sizeof...(Args) >= 1)
424 explicit FrameError(Path path, std::string_view pattern, Args&&... args)
425 : Exception(path, pattern, std::forward<Args>(args)...) {}
426
432 explicit FrameError(Path path, std::string_view message)
433 : Exception(path, message) {}
434
439 FrameError(const FrameError& other);
440
445 FrameError(FrameError&& other) noexcept;
446
450 ~FrameError() noexcept override;
451
457 FrameError& operator=(const FrameError& other);
458
464 FrameError& operator=(FrameError&& other) noexcept;
465 };
466 }
467}
468
470
471STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Network::ConnectionError);
472
473STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Network::ConnectionClosed);
474
476
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Buffer::Bridge)
~ConnectionClosed() noexcept override
Destructor.
ConnectionClosed(Path path, std::string_view pattern, Args &&... args)
Replace literal {} under an additional Network path.
Definition exception.hxx:272
ConnectionClosed(ConnectionClosed &&other) noexcept
Move the closed-connection error inside Network.
ConnectionClosed(Path path, std::string_view message)
Copy a borrowed plain message under an additional Network path.
Definition exception.hxx:280
ConnectionClosed(const ConnectionClosed &other)
Copy the closed-connection error inside Network.
ConnectionClosed(std::string_view message)
Prefix a borrowed message with Connection closed: .
Definition exception.hxx:260
ConnectionClosed(std::string_view pattern, Args &&... args)
Replace literal {}, then prefix Connection closed: .
Definition exception.hxx:252
~ConnectionError() noexcept override
Destructor.
ConnectionError(std::string_view pattern, Args &&... args)
Replace literal {} under StormByte.Network.Connection.
Definition exception.hxx:173
ConnectionError(Path path, std::string_view pattern, Args &&... args)
Replace literal {} under an additional Network path.
Definition exception.hxx:192
ConnectionError(Path path, std::string_view message)
Copy a borrowed plain message under an additional Network path.
Definition exception.hxx:200
ConnectionError(const ConnectionError &other)
Copy the connection error inside Network.
ConnectionError(ConnectionError &&other) noexcept
Move the connection error inside Network.
ConnectionError(std::string_view message)
Copy a borrowed plain message under StormByte.Network.Connection.
Definition exception.hxx:180
Exception & operator=(const Exception &other)
Copy Base-owned message storage through its provider.
Exception(Path path, std::string_view pattern, Args &&... args)
Replace literal {} under an additional Network path.
Definition exception.hxx:117
Exception(Path path, std::string_view message)
Copy a borrowed plain message under an additional Network path.
~Exception() noexcept override
Destroy the exception.
Exception(Exception &&other) noexcept
Transfer Base-owned message storage without allocating.
Exception & operator=(Exception &&other) noexcept
Transfer Base-owned message storage without allocating.
Exception(std::string_view pattern, Args &&... args)
Replace literal {} under StormByte.Network.
Definition exception.hxx:99
Exception(const Exception &other)
Copy Base-owned message storage through its provider.
Exception(std::string_view message)
Copy a borrowed plain message under StormByte.Network in the provider.
FrameError(const FrameError &other)
Copy the frame error inside Network.
FrameError(Path path, std::string_view pattern, Args &&... args)
Replace literal {} under an additional Network path.
Definition exception.hxx:424
FrameError(std::string_view message)
Copy a borrowed plain message under StormByte.Network.Transport.Frame.
Definition exception.hxx:412
~FrameError() noexcept override
Destructor.
FrameError(Path path, std::string_view message)
Copy a borrowed plain message under an additional Network path.
Definition exception.hxx:432
FrameError(FrameError &&other) noexcept
Move the frame error inside Network.
FrameError(std::string_view pattern, Args &&... args)
Replace literal {} under StormByte.Network.Transport.Frame.
Definition exception.hxx:405
PacketError(std::string_view message)
Copy a borrowed plain message under StormByte.Network.Transport.Packet.
Definition exception.hxx:336
PacketError(PacketError &&other) noexcept
Move the packet error inside Network.
~PacketError() noexcept override
Destructor.
PacketError(std::string_view pattern, Args &&... args)
Replace literal {} under StormByte.Network.Transport.Packet.
Definition exception.hxx:329
PacketError(Path path, std::string_view message)
Copy a borrowed plain message under an additional Network path.
Definition exception.hxx:356
PacketError(Path path, std::string_view pattern, Args &&... args)
Replace literal {} under an additional Network path.
Definition exception.hxx:348
PacketError(const PacketError &other)
Copy the packet error inside Network.
static String ReplaceToken(std::string_view text, Args &&... args)
Network module of the StormByte suite.
Root namespace of the StormByte suite.
STL namespace.
Additional path segments nested below StormByte.Network.
Definition exception.hxx:81
std::string_view segments
Additional dotted path segments.
Definition exception.hxx:82
constexpr Path(std::string_view segments={}) noexcept
Wraps additional path segments.
Definition exception.hxx:88
#define STORMBYTE_NETWORK_PUBLIC
Definition visibility.h:51