diff options
| author | Markus Engel <markus.engel@tum.de> | 2013-04-07 23:31:41 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2013-04-07 23:31:41 +0000 |
| commit | e9d86314ef5d8aafc2ec7677fe4825a346276ce4 (patch) | |
| tree | 59ebe8b86e8b25336a336e5d7465aa20435f00ca /src/sp-object.cpp | |
| parent | Merge Object and subclasses. Merging of SP- and C-classes complete. (diff) | |
| download | inkscape-e9d86314ef5d8aafc2ec7677fe4825a346276ce4.tar.gz inkscape-e9d86314ef5d8aafc2ec7677fe4825a346276ce4.zip | |
Added exception to SPFactory / basic handling to SPObject.
(bzr r11608.1.87)
Diffstat (limited to 'src/sp-object.cpp')
| -rw-r--r-- | src/sp-object.cpp | 71 |
1 files changed, 50 insertions, 21 deletions
diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 7d42efebe..ff5426282 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -209,6 +209,34 @@ public: } + + + + + +#include <stdexcept> +#include <exception> + +void log_exception(std::exception_ptr exception) { + try { + std::rethrow_exception(exception); + } catch (const std::exception& e) { + std::cerr << "Caught Exception of type " << std::string(typeid(e).name()) << '\n'; + std::cerr << "Message: " << std::string(e.what()) << '\n'; + + try { + std::rethrow_if_nested(e); + } catch (...) { + std::cerr << "Inner Exception: \n"; + log_exception(std::current_exception()); + } + } +} + + + + + gchar const* SPObject::getId() const { return id; } @@ -592,22 +620,17 @@ SPObject *SPObject::get_child_by_repr(Inkscape::XML::Node *repr) void SPObject::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { SPObject* object = this; -// GType type = sp_repr_type_lookup(child); -// if (!type) { -// return; -// } -// SPObject *ochild = SP_OBJECT(g_object_new(type, 0)); - - SPObject* ochild = SPFactory::instance().createObject(*child); - if (!ochild) { - return; - } + try { + SPObject* ochild = SPFactory::instance().createObject(*child); - SPObject *prev = ref ? object->get_child_by_repr(ref) : NULL; - object->attach(ochild, prev); - sp_object_unref(ochild, NULL); + SPObject *prev = ref ? object->get_child_by_repr(ref) : NULL; + object->attach(ochild, prev); + sp_object_unref(ochild, NULL); - ochild->invoke_build(object->document, child, object->cloned); + ochild->invoke_build(object->document, child, object->cloned); + } catch (const SPFactory::TypeNotRegistered& e) { + log_exception(std::current_exception()); + } } void SPObject::release() { @@ -657,14 +680,20 @@ void SPObject::build(SPDocument *document, Inkscape::XML::Node *repr) { // } // SPObject *child = SP_OBJECT(g_object_new(type, 0)); - SPObject* child = SPFactory::instance().createObject(*rchild); - if (!child) { - continue; - } +// SPObject* child = SPFactory::instance().createObject(*rchild); +// if (!child) { +// continue; +// } - object->attach(child, object->lastChild()); - sp_object_unref(child, NULL); - child->invoke_build(document, rchild, object->cloned); + try { + SPObject* child = SPFactory::instance().createObject(*rchild); + + object->attach(child, object->lastChild()); + sp_object_unref(child, NULL); + child->invoke_build(document, rchild, object->cloned); + } catch (const SPFactory::TypeNotRegistered& e) { + log_exception(std::current_exception()); + } } } |
