Commits

camlspotter committed 7921e70

added Exn.tee

Comments (0)

Files changed (2)

 let try_default' ~default f = try f () with _ -> default ();;
 let try_bool' f = try ignore (f ()); true with _ -> false
 
+let tee f v ~handler = try f v with e -> handler e; raise e
+
 (* Printexc 
 
    Printexc has a very bad name. Printexc for exn ?
 val try_bool'     : (unit -> unit) -> bool (* success/fail *)
 (** [true] at success *)
 
+val tee : ('a -> 'b) -> 'a -> handler:(exn -> unit) -> 'b
+(** [tee f v ~handler]. If [f v] raises an exception [e], 
+    [handler e] is executed, then [e] is reraised.
+*)
+
 (* Printexc + alpha *)
 
 val to_string : exn -> string