From: Mikko Rasa Date: Wed, 29 May 2013 20:17:00 +0000 (+0300) Subject: Restore parent to 0 if an exception occurs while setting things up X-Git-Url: http://git.tdb.fi/?p=libs%2Fgltk.git;a=commitdiff_plain;h=5d219b2f7e8ce196486c225e971f76ceab5538c5 Restore parent to 0 if an exception occurs while setting things up This prevents an inconsistent state from forming if something goes wrong. --- diff --git a/source/widget.cpp b/source/widget.cpp index 9dbd9da..bbd2e88 100644 --- a/source/widget.cpp +++ b/source/widget.cpp @@ -70,10 +70,20 @@ void Widget::set_parent(Container *p) throw hierarchy_error("widget already parented"); else if(p==parent) return; - parent = p; - on_reparent(); - update_style(); + try + { + parent = p; + + on_reparent(); + update_style(); + } + catch(...) + { + // The container has not yet added the widget as its child + parent = 0; + throw; + } } void Widget::set_style(const string &s)