StormByte C++ Library: System module 1.0.1.9999
StormByte-System is the C++26 process and environment module of the StormByte suite.
Loading...
Searching...
No Matches
exception.hxx
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-System.
5 *
6 * StormByte-System 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-System 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-System. If not, see
17 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
18 */
19
20#pragma once
21
22#include <StormByte/exception.hxx>
23#include <StormByte/system/visibility.h>
24
25#include <filesystem>
26
35 class STORMBYTE_SYSTEM_PUBLIC Exception: public StormByte::Exception {
36 public:
41 Exception(const std::string& message);
42
46 Exception(const Exception&) = default;
47
51 Exception(Exception&&) noexcept = default;
52
56 Exception& operator=(const Exception&) = default;
57
61 Exception& operator=(Exception&&) noexcept = default;
62
66 virtual ~Exception() noexcept override = default;
67 };
68
73 class STORMBYTE_SYSTEM_PUBLIC FileIOError final: public Exception {
74 public:
79 enum class Operation {
80 Read = 0,
81 Write
82 };
83
89 constexpr static const char* operation_to_string(const Operation& op) noexcept {
90 switch (op) {
91 case Operation::Read: return "read";
92 case Operation::Write: return "write";
93 default: return "unknown";
94 }
95 }
96
102 FileIOError(const std::filesystem::path& file, const Operation& operation);
103
107 FileIOError(const FileIOError&) = default;
108
112 FileIOError(FileIOError&&) noexcept = default;
113
117 FileIOError& operator=(const FileIOError&) = default;
118
122 FileIOError& operator=(FileIOError&&) = default;
123
127 ~FileIOError() noexcept override = default;
128 };
129
134 class STORMBYTE_SYSTEM_PUBLIC ExecutableNotFound: public Exception {
135 public:
140 ExecutableNotFound(const std::filesystem::path& exec);
141
146
151
155 ExecutableNotFound& operator=(const ExecutableNotFound&) = default;
156
160 ExecutableNotFound& operator=(ExecutableNotFound&&) noexcept = default;
161
165 ~ExecutableNotFound() noexcept override = default;
166 };
167}
Base exception for the System module.
Definition exception.hxx:35
Exception(const std::string &message)
Construct from a message.
Exception(Exception &&) noexcept=default
Move constructor.
Exception(const Exception &)=default
Copy constructor.
A program could not be executed / was not found.
Definition exception.hxx:134
ExecutableNotFound(const std::filesystem::path &exec)
Construct from an executable path or name.
ExecutableNotFound(const ExecutableNotFound &)=default
Copy constructor.
ExecutableNotFound(ExecutableNotFound &&) noexcept=default
Move constructor.
A file could not be opened for read or write.
Definition exception.hxx:73
FileIOError(const std::filesystem::path &file, const Operation &operation)
Construct from a path and an operation.
Operation
Failed file operation.
Definition exception.hxx:79
FileIOError(const FileIOError &)=default
Copy constructor.
static constexpr const char * operation_to_string(const Operation &op) noexcept
Operation as text.
Definition exception.hxx:89
FileIOError(FileIOError &&) noexcept=default
Move constructor.
System module of the StormByte suite.
Definition exception.hxx:30