Cbeam
Loading...
Searching...
No Matches
system_error.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2025 acrion innovations GmbH
3Authors: Stefan Zipproth, s.zipproth@acrion.ch
4
5This file is part of Cbeam, see https://github.com/acrion/cbeam and https://cbeam.org
6
7Cbeam is offered under a commercial and under the AGPL license.
8For commercial licensing, contact us at https://acrion.ch/sales. For AGPL licensing, see below.
9
10AGPL licensing:
11
12Cbeam is free software: you can redistribute it and/or modify
13it under the terms of the GNU Affero General Public License as published by
14the Free Software Foundation, either version 3 of the License, or
15(at your option) any later version.
16
17Cbeam is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU Affero General Public License for more details.
21
22You should have received a copy of the GNU Affero General Public License
23along with Cbeam. If not, see <https://www.gnu.org/licenses/>.
24*/
25
26#pragma once
27
28#ifdef _WIN32
30#else
31 #include <cerrno>
32#endif
33
35
36#include <string> // for std::string
37#include <system_error> // for std::system_error
38
39namespace cbeam::error
40{
81 : public virtual base_error
82 , public virtual std::system_error
83 {
84 public:
85#ifdef _WIN32
91 explicit system_error(const std::string& message = "")
92 : std::system_error(::GetLastError(), std::system_category(), message)
93 {
94 }
95#else
101 explicit system_error(const std::string& message = "")
102 : std::system_error(errno, std::generic_category(), message)
103 {
104 }
105#endif
106
110 ~system_error() override = default;
111
115 const char* what() const noexcept override
116 {
117 return std::system_error::what();
118 }
119 };
120}
base_error()=default
Default constructor.
Custom exception class for handling system-level errors in a cross-platform manner.
Definition system_error.hpp:83
system_error(const std::string &message="")
Constructs a system_error using GetLastError() on Windows.
Definition system_error.hpp:91
~system_error() override=default
Virtual destructor.
const char * what() const noexcept override
Returns the descriptive string of this error, using std::system_error::what().
Definition system_error.hpp:115
Defines Cbeam-specific exception types that behave like their standard counterparts....
Definition base_error.hpp:31
Header file to manage inclusion of windows.h with specific settings.