more precise exceptions;
authorwenzelm
Tue, 12 Jul 2011 11:16:56 +0200
changeset 43768 d52ab827d62b
parent 43767 e0219ef7f84c
child 43769 beba1a87caaa
more precise exceptions;
src/Pure/General/xml.ML
src/Pure/General/xml.scala
--- a/src/Pure/General/xml.ML	Tue Jul 12 10:44:30 2011 +0200
+++ b/src/Pure/General/xml.ML	Tue Jul 12 11:16:56 2011 +0200
@@ -324,7 +324,11 @@
   | option f [t] = SOME (f (node t))
   | option _ ts = raise XML_BODY ts;
 
-fun variant fs [t] = uncurry (nth fs) (tagged t)
+fun variant fs [t] =
+      let
+        val (tag, ts) = tagged t;
+        val f = nth fs tag handle General.Subscript => raise XML_BODY [t];
+      in f ts end
   | variant _ ts = raise XML_BODY ts;
 
 end;
--- a/src/Pure/General/xml.scala	Tue Jul 12 10:44:30 2011 +0200
+++ b/src/Pure/General/xml.scala	Tue Jul 12 11:16:56 2011 +0200
@@ -361,7 +361,10 @@
     {
       case List(t) =>
         val (tag, ts) = tagged(t)
-        fs(tag)(ts)
+        val f =
+          try { fs(tag) }
+          catch { case _: IndexOutOfBoundsException => throw new XML_Body(List(t)) }
+        f(ts)
       case ts => throw new XML_Body(ts)
     }
   }