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..e9ef93e04 100644 --- a/oxygine/src/oxygine/EventDispatcher.h +++ b/oxygine/src/oxygine/EventDispatcher.h @@ -23,6 +23,11 @@ namespace oxygine #define EventID(str) EventIDc11(str) + class event_exception : public std::runtime_error { + public: + event_exception(const char* what) : std::runtime_error(what) { } + event_exception(const event_exception &other) : event_exception(other.what()) { } + }; DECLARE_SMART(EventDispatcher, spEventDispatcher); class EventDispatcher: public Object {