From c87bf729db091bf5f31ef44b7296b298f99283bc Mon Sep 17 00:00:00 2001 From: Pablo Amorin Date: Wed, 19 Jun 2019 17:50:23 -0300 Subject: [PATCH 1/2] [Feature] Event Exception --- oxygine/src/oxygine/Event.h | 5 ++++- oxygine/src/oxygine/EventDispatcher.cpp | 8 +++++++- oxygine/src/oxygine/EventDispatcher.h | 9 +++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/oxygine/src/oxygine/Event.h b/oxygine/src/oxygine/Event.h index e79fcee66..4dfa29ea2 100644 --- a/oxygine/src/oxygine/Event.h +++ b/oxygine/src/oxygine/Event.h @@ -9,7 +9,10 @@ namespace oxygine class Event { public: - enum { COMPLETE = sysEventID('C', 'M', 'P') }; + enum { + COMPLETE = sysEventID('C', 'M', 'P'), + ERROR = sysEventID('E', 'R', 'R') + }; enum Phase { diff --git a/oxygine/src/oxygine/EventDispatcher.cpp b/oxygine/src/oxygine/EventDispatcher.cpp index 6de0c033f..3d1862786 100644 --- a/oxygine/src/oxygine/EventDispatcher.cpp +++ b/oxygine/src/oxygine/EventDispatcher.cpp @@ -203,7 +203,13 @@ namespace oxygine listenerbase& ls = copy[i]; event->currentTarget = this; event->listenerID = ls.id; - ls.cb(event); + try{ + ls.cb(event); + } catch (const oxygine::event_exception &ex) { + Event e(Event::ERROR); + e.userData = (void*) &ex; + dispatchEvent(&e); + } if (event->stopsImmediatePropagation) break; } diff --git a/oxygine/src/oxygine/EventDispatcher.h b/oxygine/src/oxygine/EventDispatcher.h index 1f3cd6e83..3546788e7 100644 --- a/oxygine/src/oxygine/EventDispatcher.h +++ b/oxygine/src/oxygine/EventDispatcher.h @@ -23,6 +23,15 @@ namespace oxygine #define EventID(str) EventIDc11(str) + class event_exception : public std::exception { + public: + event_exception(std::string what) : std::exception() { } + event_exception(const event_exception &other) : event_exception(other.what()) { } + + virtual const char* what() const _NOEXCEPT override { return _what.c_str(); } + private: + std::string _what; + }; DECLARE_SMART(EventDispatcher, spEventDispatcher); class EventDispatcher: public Object { From 22bfa7d916199c7cf8734ea733f3ae92bbed4691 Mon Sep 17 00:00:00 2001 From: Pablo Amorin Date: Wed, 19 Jun 2019 18:28:17 -0300 Subject: [PATCH 2/2] [FIX] Use correct base class --- oxygine/src/oxygine/EventDispatcher.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/oxygine/src/oxygine/EventDispatcher.h b/oxygine/src/oxygine/EventDispatcher.h index 3546788e7..e9ef93e04 100644 --- a/oxygine/src/oxygine/EventDispatcher.h +++ b/oxygine/src/oxygine/EventDispatcher.h @@ -23,14 +23,10 @@ namespace oxygine #define EventID(str) EventIDc11(str) - class event_exception : public std::exception { + class event_exception : public std::runtime_error { public: - event_exception(std::string what) : std::exception() { } + event_exception(const char* what) : std::runtime_error(what) { } event_exception(const event_exception &other) : event_exception(other.what()) { } - - virtual const char* what() const _NOEXCEPT override { return _what.c_str(); } - private: - std::string _what; }; DECLARE_SMART(EventDispatcher, spEventDispatcher); class EventDispatcher: public Object