RealTimeTransport 1.0.0
Real-time simulation of quantum transport processes
Loading...
Searching...
No Matches
Error.h
Go to the documentation of this file.
1//
2// This Source Code Form is subject to the terms of the Mozilla Public
3// License, v. 2.0. If a copy of the MPL was not distributed with this
4// file, You can obtain one at https://mozilla.org/MPL/2.0/.
5//
6
7///
8/// \file Error.h
9///
10/// \brief Contains exception/error classes.
11///
12
13#ifndef REAL_TIME_TRANSPORT_ERROR_H
14#define REAL_TIME_TRANSPORT_ERROR_H
15
16#include <source_location>
17#include <stdexcept>
18#include <string>
19#include <string_view>
20
22
23namespace RealTimeTransport
24{
25
26///
27/// @brief This class represents a generic error.
28///
29/// This class represents a generic error.
30///
32{
33 public:
34 /// @brief Default constructor.
35 Error() noexcept;
36
37 /// @brief Constructs an error with a given message.
38 Error(const std::string& message, std::source_location location = std::source_location::current());
39
40 /// @brief Move constructor.
41 Error(Error&& other) noexcept;
42
43 virtual ~Error() noexcept;
44
45 /// @brief Move assignment operator.
46 Error& operator=(Error&& other) noexcept;
47
48 /// @brief Returns the error message.
49 const char* what() const noexcept override;
50
51 private:
52 std::string _what;
53};
54
55///
56/// @brief Class representing the result of a computation that didn't meet a required accuracy goal.
57///
58/// This class represents the result of a computation that didn't meet a required accuracy goal.
59/// The class contains an error message and the preliminary result of the computation.
60///
61/// @tparam T Result type of the computation.
62///
63template <typename T>
65{
66 public:
67 /// @brief Constructs an error with a message and a preliminary value.
69 const std::string& message,
70 T&& value,
71 std::source_location location = std::source_location::current())
73 {
74 }
75
76 /// @brief Constructs an error from an \a error instance and a preliminary value.
77 AccuracyError(Error&& error, T&& value) : Error(std::move(error)), _value(std::move(value))
78 {
79 }
80
81 /// @brief Return the preliminary result of the computation.
82 T& value() noexcept
83 {
84 return _value;
85 }
86
87 /// @brief Return the preliminary result of the computation.
88 const T& value() const noexcept
89 {
90 return _value;
91 }
92
93 private:
94 T _value;
95};
96
97} // namespace RealTimeTransport
98
99#endif // REAL_TIME_TRANSPORT_ERROR_H
#define REALTIMETRANSPORT_EXPORT
Definition RealTimeTransport_export.h:15
Class representing the result of a computation that didn't meet a required accuracy goal.
Definition Error.h:65
const T & value() const noexcept
Return the preliminary result of the computation.
Definition Error.h:88
T & value() noexcept
Return the preliminary result of the computation.
Definition Error.h:82
AccuracyError(Error &&error, T &&value)
Constructs an error from an error instance and a preliminary value.
Definition Error.h:77
AccuracyError(const std::string &message, T &&value, std::source_location location=std::source_location::current())
Constructs an error with a message and a preliminary value.
Definition Error.h:68
This class represents a generic error.
Definition Error.h:32
Error() noexcept
Default constructor.
Error(Error &&other) noexcept
Move constructor.
const char * what() const noexcept override
Returns the error message.
Error(const std::string &message, std::source_location location=std::source_location::current())
Constructs an error with a given message.
Error & operator=(Error &&other) noexcept
Move assignment operator.