PMT Renovated main
Partition Manager Tool is a fast, reliable, and feature-rich CLI application for Android devices that enables advanced partition operations such as backup, flashing, erasing, information retrieval, and more.
Loading...
Searching...
No Matches
error.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Yağız Zengin
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24#ifndef LIBHELPER_ERROR_HPP
25#define LIBHELPER_ERROR_HPP
26
27#include <exception>
28#include <sstream>
29#include <string>
30#include <format>
31#include <libhelper/logging.hpp>
32
33namespace Helper {
34
65class Error final : public std::exception {
67 std::string message;
68 int ec = 0;
69
70public:
71 Error() = default;
72
74 Error(const Error &other) noexcept : message(other.message) {}
75
77 template <typename... Args> explicit Error(std::format_string<Args...> fmt, Args &&...args) {
78 oss << std::format(fmt, std::forward<Args>(args)...);
79 message = oss.str();
80 }
81
83 template <typename T> Error &&operator<<(const T &msg) && {
84 oss << msg;
85 message = oss.str();
86 return std::move(*this);
87 }
88
91 oss << msg;
92 message = oss.str();
93 return *this;
94 }
95
97 Error &&withCode(int _ec) {
98 ec = _ec;
99 return std::move(*this);
100 }
101
103 int getErrorCode() const { return ec; }
104
106 [[nodiscard]] const char *what() const noexcept override { return message.data(); }
107};
108
109} // namespace Helper
110
111#endif // #ifndef LIBHELPER_ERROR_HPP
A modern, throwable error class. It provides the << operator and offers usage in the std::print style...
Definition error.hpp:65
Error && withCode(int _ec)
It is used to determine the error code when an error is thrown.
Definition error.hpp:97
int getErrorCode() const
Get error code.
Definition error.hpp:103
Error(const Error &other) noexcept
Copy constructor.
Definition error.hpp:74
Error(std::format_string< Args... > fmt, Args &&...args)
Modern std::print style input field constructor.
Definition error.hpp:77
Error && operator<<(const T &msg) &&
To use the << operator for receiving non-function-like inputs.
Definition error.hpp:83
const char * what() const noexcept override
Get error message.
Definition error.hpp:106
Error & operator<<(std::ostream &(*msg)(std::ostream &))
To receive function-like inputs, use the << operator.
Definition error.hpp:90
T data(T... args)
T forward(T... args)
A logging solution that can be used throughout the program(s).
Main namespace of libhelper library.
Definition capsule.hpp:27