# HG changeset patch # User deba # Date 1157368199 0 # Node ID ef3560193856020e03d55e068cc28921ad90dac5 # Parent dd887831e9c1c953a60087eef1174351ee117a04 Proper exception handling in the SmartEdgeSet diff -r dd887831e9c1 -r ef3560193856 lemon/edge_set.h --- a/lemon/edge_set.h Mon Sep 04 11:09:13 2006 +0000 +++ b/lemon/edge_set.h Mon Sep 04 11:09:59 2006 +0000 @@ -602,7 +602,7 @@ Parent::OutEdgeIt(*this, node) == INVALID) { return; } - throw UnsupportedOperation(); + throw typename NodesImplBase::Notifier::ImmediateDetach(); } void clearNodes() { @@ -621,14 +621,22 @@ protected: virtual void erase(const Node& node) { - _edgeset.eraseNode(node); - Parent::erase(node); + try { + _edgeset.eraseNode(node); + Parent::erase(node); + } catch (const typename NodesImplBase::Notifier::ImmediateDetach&) { + Parent::clear(); + } } virtual void erase(const std::vector& nodes) { - for (int i = 0; i < (int)nodes.size(); ++i) { - _edgeset.eraseNode(nodes[i]); + try { + for (int i = 0; i < (int)nodes.size(); ++i) { + _edgeset.eraseNode(nodes[i]); + } + Parent::erase(nodes); + } catch (const typename NodesImplBase::Notifier::ImmediateDetach&) { + Parent::clear(); } - Parent::erase(nodes); } virtual void clear() { _edgeset.clearNodes(); @@ -681,13 +689,6 @@ typedef _Graph Graph; - class UnsupportedOperation : public LogicError { - public: - virtual const char* what() const throw() { - return "lemon::SmartUEdgeSet::UnsupportedOperation"; - } - }; - protected: typedef typename Parent::NodesImplBase NodesImplBase; @@ -696,7 +697,7 @@ if (typename Parent::IncEdgeIt(*this, node) == INVALID) { return; } - throw UnsupportedOperation(); + throw typename NodesImplBase::Notifier::ImmediateDetach(); } void clearNodes() { @@ -715,14 +716,22 @@ protected: virtual void erase(const Node& node) { - _edgeset.eraseNode(node); - Parent::erase(node); + try { + _edgeset.eraseNode(node); + Parent::erase(node); + } catch (const typename NodesImplBase::Notifier::ImmediateDetach&) { + Parent::clear(); + } } virtual void erase(const std::vector& nodes) { - for (int i = 0; i < (int)nodes.size(); ++i) { - _edgeset.eraseNode(nodes[i]); - } - Parent::erase(nodes); + try { + for (int i = 0; i < (int)nodes.size(); ++i) { + _edgeset.eraseNode(nodes[i]); + } + Parent::erase(nodes); + } catch (const typename NodesImplBase::Notifier::ImmediateDetach&) { + Parent::clear(); + } } virtual void clear() { _edgeset.clearNodes();