src/Pure/General/exn.scala
author blanchet
Thu, 16 Dec 2010 22:45:02 +0100
changeset 41220 4d11b0de7dd8
parent 34313 2f890016afab
child 43761 e72ba84ae58f
permissions -rw-r--r--
discriminate SMT errors a bit better

/*  Title:      Pure/General/exn.scala
    Author:     Makarius

Extra support for exceptions (arbitrary throwables).
*/

package isabelle


object Exn
{
  /* runtime exceptions as values */

  sealed abstract class Result[A]
  case class Res[A](val result: A) extends Result[A]
  case class Exn[A](val exn: Throwable) extends Result[A]

  def capture[A](e: => A): Result[A] =
    try { Res(e) }
    catch { case exn: Throwable => Exn[A](exn) }

  def release[A](result: Result[A]): A =
    result match {
      case Res(x) => x
      case Exn(exn) => throw exn
    }
}