StormByte C++ Library 1.2.0
StormByte is a comprehensive, cross-platform C++ library aimed at easing system programming, configuration management, logging, and database handling tasks. This library provides a unified API that abstracts away the complexities and inconsistencies of different platforms (Windows, Linux).
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.
5 *
6 * StormByte 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 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. If not, see
17 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
18 */
19
20#pragma once
21
23#include <string>
24#include <string_view>
25#include <format>
26
31namespace StormByte {
41 struct Component {
42 std::string_view name;
43
48 constexpr explicit Component(std::string_view name) noexcept: name(name) {}
49 };
50
58 public:
63 explicit Exception(const std::string& message);
64
69 explicit Exception(std::string&& message);
70
78 template <typename... Args>
79 Exception(std::format_string<Args...> fmt, Args&&... args) {
80 if constexpr (sizeof...(Args) == 0) {
81 m_what = copy_str(std::string(fmt.get()).c_str());
82 } else {
83 std::string formatted_message = std::format(fmt, std::forward<Args>(args)...);
84 m_what = copy_str(formatted_message.c_str());
85 }
86 }
87
96 template <typename... Args>
97 Exception(Component component, std::format_string<Args...> fmt, Args&&... args) {
98 std::string formatted_message = std::format(fmt, std::forward<Args>(args)...);
99 std::string full_message = "StormByte::" + std::string(component.name) + ": " + formatted_message;
100 m_what = copy_str(full_message.c_str());
101 }
102
108
113 Exception(Exception&& e) noexcept;
114
118 virtual ~Exception() noexcept;
119
125 Exception& operator=(const Exception& e);
126
132 Exception& operator=(Exception&& e) noexcept;
133
138 virtual const char* what() const noexcept;
139
140 private:
141 const char* m_what;
142
148 const char* copy_str(const char* str) noexcept;
149
153 void free_str() noexcept;
154 };
155
161 public:
162 using Exception::Exception;
163 };
164
170 public:
171 using Exception::Exception;
172 };
173
179 public:
180 using Exception::Exception;
181 };
182
188 public:
189 using Exception::Exception;
190 };
191
197 public:
198 using Exception::Exception;
199 };
200}
Thrown when Base64 encode or decode fails.
Definition exception.hxx:178
Thrown when deserialization fails.
Definition exception.hxx:160
Base exception type for the suite.
Definition exception.hxx:57
Exception(const std::string &message)
Constructs from a string.
Exception(std::string &&message)
Constructs from a moved string.
Exception(Exception &&e) noexcept
Move constructor.
Exception(const Exception &e)
Copy constructor.
Exception(Component component, std::format_string< Args... > fmt, Args &&... args)
Constructs with a component prefix and std::format.
Definition exception.hxx:97
Exception(std::format_string< Args... > fmt, Args &&... args)
Constructs with std::format.
Definition exception.hxx:79
virtual ~Exception() noexcept
Destructor.
Thrown when an index or range is out of bounds.
Definition exception.hxx:169
Thrown when a System helper cannot obtain a path or create a temporary file.
Definition exception.hxx:196
Thrown when UTF-8 or wide-string input contains invalid Unicode.
Definition exception.hxx:187
Root namespace of the StormByte suite.
Wraps a module name for the component-prefixed Exception constructor.
Definition exception.hxx:41
constexpr Component(std::string_view name) noexcept
Wraps name.
Definition exception.hxx:48
std::string_view name
Module name inserted after StormByte::.
Definition exception.hxx:42
#define STORMBYTE_PUBLIC
Definition visibility.h:28