aboutsummaryrefslogtreecommitdiffstats
path: root/bindings/cxx/include/pugl/pugl.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-10-31 13:00:49 +0100
committerDavid Robillard <d@drobilla.net>2020-10-31 13:00:49 +0100
commit5676ec170aab822f01523fb65a634ca822ee0d03 (patch)
treef86157c15c1a3dfc241d3801f184cef2672510ca /bindings/cxx/include/pugl/pugl.hpp
parent5d7ddd8c2d714439ad07b54622600b11a9e980a0 (diff)
downloadpugl-5676ec170aab822f01523fb65a634ca822ee0d03.tar.gz
pugl-5676ec170aab822f01523fb65a634ca822ee0d03.tar.bz2
pugl-5676ec170aab822f01523fb65a634ca822ee0d03.zip
Use a custom exception type for failed construction
This avoids an include of <exception>, which is slow, and is better practice anyway.
Diffstat (limited to 'bindings/cxx/include/pugl/pugl.hpp')
-rw-r--r--bindings/cxx/include/pugl/pugl.hpp22
1 files changed, 18 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);