summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-08-04 13:02:38 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-08-04 13:02:38 +0100
commit39798db6b8669a8d3b4605a0bc8bb70d65f0b0aa (patch)
tree4e08dc979793fdc59580604509c81628fb4386cd /lib
parentSplit CheckShaderError into shader/program versions (diff)
downloadilt-39798db6b8669a8d3b4605a0bc8bb70d65f0b0aa.tar.bz2
ilt-39798db6b8669a8d3b4605a0bc8bb70d65f0b0aa.tar.xz
ilt-39798db6b8669a8d3b4605a0bc8bb70d65f0b0aa.zip
Help exception class for lazy/cached message content
Diffstat (limited to 'lib')
-rw-r--r--lib/msgException.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/msgException.h b/lib/msgException.h
new file mode 100644
index 0000000..660738d
--- /dev/null
+++ b/lib/msgException.h
@@ -0,0 +1,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;
+};