let finalize f g = match try `Ok (f ()) with e -> `Exn e with `Ok x -> g (); x | `Exn e -> g (); raise e