src/Pure/ML-Systems/exn.ML
author wenzelm
Thu, 09 Aug 2007 23:53:50 +0200
changeset 24208 f4cafbaa05e4
parent 23962 e0358fac0541
child 28444 283d5e41953d
permissions -rw-r--r--
schedule: more precise task model; improved error handling: first failure causes interrupt of all threads; misc cleanup;

(*  Title:      Pure/ML-Systems/exn.ML
    ID:         $Id$
    Author:     Makarius

Runtime exceptions as values.
*)

structure Exn =
struct

datatype 'a result =
  Result of 'a |
  Exn of exn;

fun get_result (Result x) = SOME x
  | get_result _ = NONE;

fun get_exn (Exn exn) = SOME exn
  | get_exn _ = NONE;

fun capture f x = Result (f x) handle e => Exn e;

fun release (Result y) = y
  | release (Exn e) = raise e;

exception EXCEPTIONS of exn list * string;

end;