aboutsummaryrefslogtreecommitdiffstats
path: root/bindings/cxx
diff options
context:
space:
mode:
Diffstat (limited to 'bindings/cxx')
-rw-r--r--bindings/cxx/include/pugl/pugl.hpp22
-rw-r--r--bindings/cxx/include/pugl/pugl.ipp6
2 files changed, 24 insertions, 4 deletions
diff --git a/bindings/cxx/include/pugl/pugl.hpp b/bindings/cxx/include/pugl/pugl.hpp
index 19cf3fe..ec9ca20 100644
--- a/bindings/cxx/include/pugl/pugl.hpp
+++ b/bindings/cxx/include/pugl/pugl.hpp
@@ -26,7 +26,7 @@
#include <cassert>
#include <cstdint>
-#include <stdexcept>
+#include <exception>
#include <type_traits>
namespace pugl {
@@ -236,6 +236,20 @@ static_assert(WorldFlag(PUGL_WORLD_THREADS) == WorldFlag::threads, "");
using WorldFlags = PuglWorldFlags; ///< @copydoc PuglWorldFlags
+/// An exception thrown when construction fails
+class FailedConstructionError : public std::exception
+{
+public:
+ FailedConstructionError(const char* const msg) noexcept
+ : _msg{msg}
+ {}
+
+ virtual const char* what() const noexcept override;
+
+private:
+ const char* _msg;
+};
+
/// @copydoc PuglWorld
class World : public detail::Wrapper<PuglWorld, puglFreeWorld>
{
@@ -250,7 +264,7 @@ public:
: Wrapper{puglNewWorld(static_cast<PuglWorldType>(type), flags)}
{
if (!cobj()) {
- throw std::runtime_error("Failed to create pugl::World");
+ throw FailedConstructionError("Failed to create pugl::World");
}
}
@@ -258,7 +272,7 @@ public:
: World{type, {}}
{
if (!cobj()) {
- throw std::runtime_error("Failed to create pugl::World");
+ throw FailedConstructionError("Failed to create pugl::World");
}
}
@@ -342,7 +356,7 @@ public:
, _world(world)
{
if (!cobj()) {
- throw std::runtime_error("Failed to create pugl::View");
+ throw FailedConstructionError("Failed to create pugl::View");
}
puglSetHandle(cobj(), this);
diff --git a/bindings/cxx/include/pugl/pugl.ipp b/bindings/cxx/include/pugl/pugl.ipp
index 59fb806..b90c878 100644
--- a/bindings/cxx/include/pugl/pugl.ipp
+++ b/bindings/cxx/include/pugl/pugl.ipp
@@ -25,6 +25,12 @@
namespace pugl {
+const char*
+FailedConstructionError::what() const noexcept
+{
+ return _msg;
+}
+
Status
View::onCreate(const CreateEvent&)
{