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
62
67 Exception(Exception&& e) noexcept;
68
73
80
87
93
94 private:
95 const char* m_what;
96
102 const char* copy_str(const char* str) noexcept;
103
107 void free_str() noexcept;
108 };
109}
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.
Main namespace for the StormByte library.
std::conditional_t< is_reference< T >::value, std::expected< std::reference_wrapper< std::remove_reference_t< T > >, std::shared_ptr< E > >, std::expected< T, std::shared_ptr< E > > > Expected
Expected type with support for reference types.
Definition expected.hxx:32