diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-11-24 18:59:16 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-11-24 18:59:16 +0100 |
commit | 9800cff631f1a82ee87005aabdefb3f5da7fadb5 (patch) | |
tree | 0a2de716518eb8e5a10e6f276dc2574ab0f0c420 | |
parent | 84a6eb51b0c54e8f2c5134ff9e3baf39f5da77cb (diff) |
Throw InitException on mglpp init failure
-rw-r--r-- | include/mglpp/mglpp.hpp | 10 | ||||
-rw-r--r-- | src/mglpp.cpp | 3 |
2 files changed, 12 insertions, 1 deletions
diff --git a/include/mglpp/mglpp.hpp b/include/mglpp/mglpp.hpp index 6e790af..dacd134 100644 --- a/include/mglpp/mglpp.hpp +++ b/include/mglpp/mglpp.hpp @@ -1,9 +1,19 @@ #ifndef MGLPP_MGLPP_HPP #define MGLPP_MGLPP_HPP +#include <stdexcept> + namespace mgl { + class InitException : public std::exception { + public: + const char* what() const noexcept override { + return "Failed to initialize mgl"; + } + }; + class Init { public: + // Throws InitException on failure Init(); ~Init(); }; diff --git a/src/mglpp.cpp b/src/mglpp.cpp index 6bf6307..1719d85 100644 --- a/src/mglpp.cpp +++ b/src/mglpp.cpp @@ -5,7 +5,8 @@ extern "C" { namespace mgl { Init::Init() { - mgl_init(); + if(mgl_init() != 0) + throw InitException(); } Init::~Init() { |