StormByte C++ Library: Buffer module 1.2.0
StormByte-Buffer is the buffer module of the StormByte C++ 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-Buffer.
5 *
6 * StormByte-Buffer is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version 3
8 * or later, as published by the Free Software Foundation.
9 *
10 * StormByte-Buffer is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with StormByte-Buffer. If not, see
17 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
18 */
19
20#pragma once
21
23#include <StormByte/exception.hxx>
24
25#include <format>
26#include <string>
27#include <utility>
28
33namespace StormByte::Buffer {
43 class STORMBYTE_BUFFER_PUBLIC Exception: public StormByte::Exception {
44 public:
49 explicit Exception(const std::string& message):
50 StormByte::Exception(StormByte::Component{"Buffer"}, "{}", message) {}
51
56 explicit Exception(std::string&& message):
57 StormByte::Exception(StormByte::Component{"Buffer"}, "{}", std::move(message)) {}
58
66 template <typename... Args>
67 Exception(StormByte::Component component, std::format_string<Args...> fmt, Args&&... args):
68 StormByte::Exception(component, fmt, std::forward<Args>(args)...) {}
69
76 template <typename... Args>
77 Exception(std::format_string<Args...> fmt, Args&&... args):
78 StormByte::Exception(StormByte::Component{"Buffer"}, fmt, std::forward<Args>(args)...) {}
79 };
80
91 public:
92 using Exception::Exception;
93 };
94
102 public:
107 explicit ReadError(const std::string& message):
108 Error(StormByte::Component{"Buffer::ReadError"}, "{}", message) {}
109
114 explicit ReadError(std::string&& message):
115 Error(StormByte::Component{"Buffer::ReadError"}, "{}", std::move(message)) {}
116
123 template <typename... Args>
124 ReadError(std::format_string<Args...> fmt, Args&&... args):
125 Error(StormByte::Component{"Buffer::ReadError"}, fmt, std::forward<Args>(args)...) {}
126 };
127
135 public:
140 explicit WriteError(const std::string& message):
141 Error(StormByte::Component{"Buffer::WriteError"}, "{}", message) {}
142
147 explicit WriteError(std::string&& message):
148 Error(StormByte::Component{"Buffer::WriteError"}, "{}", std::move(message)) {}
149
156 template <typename... Args>
157 WriteError(std::format_string<Args...> fmt, Args&&... args):
158 Error(StormByte::Component{"Buffer::WriteError"}, fmt, std::forward<Args>(args)...) {}
159 };
160}
General exception class for buffer errors.
Definition exception.hxx:90
Base exception type for the Buffer module.
Definition exception.hxx:43
Exception(StormByte::Component component, std::format_string< Args... > fmt, Args &&... args)
Construct a Buffer exception with an explicit component.
Definition exception.hxx:67
Exception(const std::string &message)
Construct a Buffer exception from an unformatted message.
Definition exception.hxx:49
Exception(std::format_string< Args... > fmt, Args &&... args)
Construct a Buffer exception with a formatted message.
Definition exception.hxx:77
Exception(std::string &&message)
Construct a Buffer exception from a moved unformatted message.
Definition exception.hxx:56
Exception thrown when a buffer read / extract / peek operation fails.
Definition exception.hxx:101
ReadError(std::string &&message)
Construct a read error from a moved unformatted message.
Definition exception.hxx:114
ReadError(const std::string &message)
Construct a read error from an unformatted message.
Definition exception.hxx:107
ReadError(std::format_string< Args... > fmt, Args &&... args)
Construct a read error with a format message.
Definition exception.hxx:124
Exception thrown when a buffer write operation fails.
Definition exception.hxx:134
WriteError(const std::string &message)
Construct a write error from an unformatted message.
Definition exception.hxx:140
WriteError(std::format_string< Args... > fmt, Args &&... args)
Construct a write error with a format message.
Definition exception.hxx:157
WriteError(std::string &&message)
Construct a write error from a moved unformatted message.
Definition exception.hxx:147
Buffer module of the StormByte suite.
#define STORMBYTE_BUFFER_PUBLIC
Definition visibility.h:28