blob: 660738df6063adbce5e364b1ae4775c16179ebad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#pragma once
#include <optional>
#include <string>
template<typename BaseException> class MsgException : public BaseException {
protected:
using BaseException::BaseException;
[[nodiscard]] virtual std::string getMsg() const noexcept = 0;
public:
[[nodiscard]] const char *
what() const noexcept override
{
if (!msg) {
msg.emplace(getMsg());
}
return msg->c_str();
}
private:
mutable std::optional<std::string> msg;
};
|