#pragma once #include #include template 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 msg; };