some support to recover from spurious crash -- this is Physics, not Mathematics;
authorwenzelm
Fri, 07 Dec 2012 16:33:17 +0100
changeset 50423 027d405951c8
parent 50422 ee729dbd1b7f
child 50424 7c8ce63a3c00
some support to recover from spurious crash -- this is Physics, not Mathematics;
src/Pure/General/exn.scala
--- a/src/Pure/General/exn.scala	Fri Dec 07 16:25:33 2012 +0100
+++ b/src/Pure/General/exn.scala	Fri Dec 07 16:33:17 2012 +0100
@@ -45,5 +45,23 @@
 
   def message(exn: Throwable): String =
     user_message(exn) getOrElse exn.toString
+
+
+  /* recover from spurious crash */
+
+  def recover[A](e: => A): A =
+  {
+    capture(e) match {
+      case Res(x) => x
+      case Exn(exn) =>
+        capture(e) match {
+          case Res(x) =>
+            java.lang.System.err.println("Recovered from spurious crash after retry!")
+            exn.printStackTrace()
+            x
+          case Exn(_) => throw exn
+        }
+    }
+  }
 }