StormByte C++ Library 0.0.9999
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
1#pragma once
2
3#include <StormByte/visibility.h>
4#include <string>
5#include <format>
6
14namespace StormByte {
23 class STORMBYTE_PUBLIC Exception {
24 public:
29 explicit Exception(const std::string& message);
30
35 explicit Exception(std::string&& message);
36
45 template <typename... Args>
46 Exception(std::format_string<Args...> fmt, Args&&... args) {
47 if constexpr (sizeof...(Args) == 0) {
48 // No arguments provided, use the format string directly
49 m_what = copy_str(fmt);
50 } else {
51 // Format the message with the provided arguments
52 std::string formatted_message = std::format(fmt, std::forward<Args>(args)...);
53 m_what = copy_str(formatted_message.c_str());
54 }
55 }
56
57 template <typename... Args>
58 Exception(const std::string& component, std::format_string<Args...> fmt, Args&&... args) {
59 std::string formatted_message = std::format(fmt, std::forward<Args>(args)...);
60 std::string full_message = "StormByte::" +component + ": " + formatted_message;
61 m_what = copy_str(full_message.c_str());
62 }
63
69
74 Exception(Exception&& e) noexcept;
75
79 virtual ~Exception() noexcept;
80
86 Exception& operator=(const Exception& e);
87
93 Exception& operator=(Exception&& e) noexcept;
94
99 virtual const char* what() const noexcept;
100
101 private:
102 const char* m_what;
103
109 const char* copy_str(const char* str) noexcept;
110
114 void free_str() noexcept;
115 };
116
121 class STORMBYTE_PUBLIC DeserializeError: public Exception {
122 public:
123 using Exception::Exception;
124 };
125
130 class STORMBYTE_PUBLIC OutOfBoundsError: public Exception {
131 public:
132 using Exception::Exception;
133 };
134}
Exception thrown during deserialization errors.
Definition exception.hxx:121
Base class for exceptions in the StormByte library.
Definition exception.hxx:23
Exception(const std::string &message)
Constructor.
Exception(std::string &&message)
Constructor.
Exception(Exception &&e) noexcept
Move constructor.
Exception(const Exception &e)
Copy constructor.
Exception(std::format_string< Args... > fmt, Args &&... args)
Constructor forwards the message to the std::format function.
Definition exception.hxx:46
virtual ~Exception() noexcept
Destructor.
Exception thrown when an out-of-bounds access is attempted.
Definition exception.hxx:130
Main namespace for the StormByte library.