| 1 |
#ifndef MSXEXCEPTION_HH |
| 2 |
#define MSXEXCEPTION_HH |
| 3 |
|
| 4 |
#include "strCat.hh" |
| 5 |
|
| 6 |
#include <concepts> |
| 7 |
#include <string> |
| 8 |
|
| 9 |
namespace openmsx { |
| 10 |
|
| 11 |
class MSXException |
| 12 |
{ |
| 13 |
public: |
| 14 |
explicit MSXException() = default; |
| 15 |
|
| 16 |
explicit MSXException(std::string message_) |
| 17 |
: message(std::move(message_)) {} |
| 18 |
|
| 19 |
template<typename T, typename... Args> |
| 20 |
requires(!std::same_as<MSXException, std::remove_cvref_t<T>>) |
| 21 |
explicit MSXException(T&& t, Args&&... args) |
| 22 |
: message(strCat(std::forward<T>(t), std::forward<Args>(args)...)) |
| 23 |
{ |
| 24 |
} |
| 25 |
|
| 26 |
[[nodiscard]] const std::string& getMessage() const & { return message; } |
| 27 |
[[nodiscard]] std::string getMessage() && { return std::move(message); } |
| 28 |
|
| 29 |
private: |
| 30 |
std::string message; |
| 31 |
}; |
| 32 |
|
| 33 |
class FatalError |
| 34 |
{ |
| 35 |
public: |
| 36 |
explicit FatalError(std::string message_) |
| 37 |
: message(std::move(message_)) {} |
| 38 |
|
| 39 |
template<typename T, typename... Args> |
| 40 |
requires(!std::same_as<FatalError, std::remove_cvref_t<T>>) |
| 41 |
explicit FatalError(T&& t, Args&&... args) |
| 42 |
: message(strCat(std::forward<T>(t), std::forward<Args>(args)...)) |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
[[nodiscard]] const std::string& getMessage() const & { return message; } |
| 47 |
[[nodiscard]] std::string getMessage() && { return std::move(message); } |
| 48 |
|
| 49 |
private: |
| 50 |
std::string message; |
| 51 |
}; |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
#endif |