cpp-terminal 1.0.0
Small C++ library for writing multiplatform terminal applications
Loading...
Searching...
No Matches
exception.hpp
Go to the documentation of this file.
1/*
2* cpp-terminal
3* C++ library for writing multi-platform terminal applications.
4*
5* SPDX-FileCopyrightText: 2019-2024 cpp-terminal
6*
7* SPDX-License-Identifier: MIT
8*/
9
10#pragma once
11
13
14#include <cstdint>
15#include <string>
16
17namespace Term
18{
19
20namespace Private
21{
22
23#if defined(_WIN32)
25{
26public:
27 WindowsError(const WindowsError&) = default;
29 WindowsError() noexcept = default;
30 virtual ~WindowsError() noexcept = default;
31 WindowsError& operator=(WindowsError&&) noexcept = default;
32 WindowsError& operator=(const WindowsError&) noexcept = default;
33 std::int64_t error() const noexcept;
34 bool check_value() const noexcept;
35 WindowsError& check_if(const bool& ret) noexcept;
36 void throw_exception(const std::string& str = std::string()) const;
37
38private:
39 std::int64_t m_error{0};
40 bool m_check_value{false};
41};
42
44{
45public:
46 WindowsException(const std::int64_t& error, const std::string& context = std::string());
47 ~WindowsException() override = default;
48
49private:
50 void build_what() const noexcept final;
51};
52#endif
53
54class Errno
55{
56public:
57 Errno(const Errno&) noexcept = default;
58 Errno(Errno&&) noexcept = default;
59 Errno() noexcept;
60 virtual ~Errno() noexcept;
61 Errno& operator=(Errno&&) noexcept = default;
62 Errno& operator=(const Errno&) noexcept = default;
63 std::int64_t error() const noexcept;
64 bool check_value() const noexcept;
65 Errno& check_if(const bool& ret) noexcept;
66 void throw_exception(const std::string& str = {}) const;
67
68private:
69 std::int64_t m_errno{0};
70 bool m_check_value{false};
71};
72
74{
75public:
76 ErrnoException(const ErrnoException&) = default;
78 explicit ErrnoException(const std::int64_t& error, const std::string& context = {});
79 ~ErrnoException() override = default;
82
83private:
84 void build_what() const noexcept final;
85};
86
87enum class ExceptionDestination : std::uint8_t
88{
89 MessageBox = 0,
90 StdErr,
91};
92
93void ExceptionHandler(const ExceptionDestination& destination = ExceptionDestination::StdErr) noexcept;
94
95} // namespace Private
96
97} // namespace Term
std::string context() const noexcept
Definition exception.cpp:53
ErrnoException & operator=(const ErrnoException &)=default
ErrnoException & operator=(ErrnoException &&)=default
ErrnoException(ErrnoException &&)=default
~ErrnoException() override=default
ErrnoException(const ErrnoException &)=default
Errno(Errno &&) noexcept=default
Errno(const Errno &) noexcept=default
WindowsError() noexcept=default
bool check_value() const noexcept
Definition exception.cpp:73
WindowsError & check_if(const bool &ret) noexcept
Definition exception.cpp:75
std::int64_t error() const noexcept
Definition exception.cpp:71
WindowsError(WindowsError &&)=default
void throw_exception(const std::string &str=std::string()) const
Definition exception.cpp:82
WindowsError(const WindowsError &)=default
WindowsException(const std::int64_t &error, const std::string &context=std::string())
Definition exception.cpp:87
~WindowsException() override=default
void build_what() const noexcept final
Definition args.cpp:13