Here is an example of giving an exception as an argument to a function: let run_or ~cmd ~err = if Sys.command cmd <> 0 then raise err and an example usage: let config_fail = Failure ("Could not configure " ^ p.id) in run_or ~cmd:("sh configure" ^ config_opt) ~err:config_fail; The problem with your code seems to be that you're passing in a result, so the exception is being raised outside your try...with block. OCaml's eager evaluation means that you'll probably have to pass in a function and an argument (or just a unit function), meaning that your <|||> will be much uglier: let (<|||>) (f,x) (g,y) = try f x with Nothing -> g y ((fun () -> raise Nothing), ()) <|||> ((fun str -> str), "ii") E. On Fri, Feb 17, 2012 at 1:16 PM, Pierre-Alexandre Voye wrote: > Hello, I'm trying to implement a scala concept "partial application" in > which one can chains pattern matching function. If the first failed, the > second is tried. > It seems it is impossible to give an exception as argument to a function. > > > > exception Nothing;; > > let (<|||>) a b = try a > with > > | Nothing -> (try b > with > > | Nothing -> raise > Nothing);; > > val ( <|||> ) : 'a -> 'a -> 'a = > > > > (raise Nothing) <|||> > "jj";; > > Exception: Nothing. > > > But if I try : > try (raise Nothing) > with > > | Nothing -> (try > "jj"with > > | Nothing -> raise > Nothing);; > > - : string = "jj" > > Is there a workaround ? > > > Regards, > P-A > -- > --------------------- > https://twitter.com/#!/ontologiae/ > http://linuxfr.org/users/montaigne > >