Index: lemon/bits/alteration_notifier.h
===================================================================
--- lemon/bits/alteration_notifier.h	(revision 2006)
+++ lemon/bits/alteration_notifier.h	(revision 2188)
@@ -67,13 +67,19 @@
   /// The alteration can be observed with a class inherited from the
   /// \e ObserverBase nested class. The signals can be handled with
-  /// overriding the virtual functions defined in the base class.
-  /// The observer base can be attached to the notifier with the
-  /// \e attach() member and can be detached with detach() function.
-  ///
-  /// Alteration observers try to be exception safe. This can be achived
-  /// when the observers does not throw exception on \e erase() and 
-  /// \e clear(). Less strict condition is that the \e erase() should
-  /// not throw exception after an \e add() with the same parameter and
-  /// the \e clear() should not throw exception after a \e build(). 
+  /// overriding the virtual functions defined in the base class.  The
+  /// observer base can be attached to the notifier with the 
+  /// \e attach() member and can be detached with detach() function. The
+  /// alteration handlers should not call any function which signals
+  /// an other alteration in the same notifier and should not
+  /// detach any observer from the notifier.
+  ///
+  /// Alteration observers try to be exception safe. If an \e add() or
+  /// a \e clear() function throws an exception then the remaining
+  /// observeres will not be notified and the fulfilled additions will
+  /// be rolled back by calling the \e erase() or \e clear()
+  /// functions. Thence the \e erase() and \e clear() should not throw
+  /// exception. Actullay, it can be throw only 
+  /// \ref AlterationObserver::ImmediateDetach ImmediateDetach
+  /// exception which detach the observer from the notifier.
   ///
   /// There are some place when the alteration observing is not completly
@@ -100,4 +106,14 @@
     typedef _Item Item;
 
+    /// \brief Exception which can be called from \e clear() and 
+    /// \e erase().
+    ///
+    /// From the \e clear() and \e erase() function only this
+    /// exception is allowed to throw. The exception immediatly
+    /// detaches the current observer from the notifier. Because the
+    /// \e clear() and \e erase() should not throw other exceptions
+    /// it can be used to invalidate the observer.
+    struct ImmediateDetach {};
+
     /// \brief ObserverBase is the base class for the observers.
     ///
@@ -161,5 +177,5 @@
 	notifier->attach(*this);
       }
-
+      
       /// \brief Detaches the observer into an AlterationNotifier.
       ///
@@ -169,6 +185,5 @@
         notifier->detach(*this);
       }
-	
-
+      
       /// \brief Gives back a pointer to the notifier which the map 
       /// attached into.
@@ -431,8 +446,13 @@
     /// the container.
     /// 
-    void erase(const Item& key) {
-      typename Observers::iterator it;
-      for (it = observers.begin(); it != observers.end(); ++it) {
-	(*it)->erase(key);
+    void erase(const Item& key) throw() {
+      int i = 0;
+      while (i != (int)observers.size()) {
+        try {
+          observers[i]->erase(key);
+          ++i;
+        } catch (const ImmediateDetach&) {
+          observers[i]->detach();
+        }
       }
     }
@@ -445,7 +465,12 @@
     /// 
     void erase(const std::vector<Item>& items) {
-      typename Observers::iterator it;
-      for (it = observers.begin(); it != observers.end(); ++it) {
-	(*it)->erase(items);
+      int i = 0;
+      while (i != (int)observers.size()) {
+        try {
+          observers[i]->erase(items);
+          ++i;
+        } catch (const ImmediateDetach&) {
+          observers[i]->detach();
+        }
       }
     }
@@ -471,5 +496,4 @@
     }
 
-
     /// \brief Notifies all the registed observers about all items are 
     /// erased.
@@ -478,7 +502,12 @@
     /// from the container.
     void clear() {
-      typename Observers::iterator it;
-      for (it = observers.begin(); it != observers.end(); ++it) {
-	(*it)->clear();
+      int i = 0;
+      while (i != (int)observers.size()) {
+        try {
+          observers[i]->clear();
+          ++i;
+        } catch (const ImmediateDetach&) {
+          observers[i]->detach();
+        }
       }
     }
