Version française
Home     About     Download     Resources     Contact us    
Browse thread
exception Failure and failwith
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Julien Signoles <Julien.Signoles@l...>
Subject: Re: [Caml-list] exception Failure and failwith

> It's all about the failwith function of pervasives (that simply raises
> an exception Failure of string).
> Normally, that exception can be cought by means of a try...with using as
> clause something like
> | Failure s -> .....
>
> But what if I want to catch the Failure exception? :-/
> It seems that no module defines it, so I did not find any way to
> identify the exception.

You're right: no module defines Failure. But you can make an alias for the
primitive Failure and use it:

==========
exception Prim_Failure = Failure
exception Failure
let f () = failwith ""
let () =
  try f (); assert false
  with Prim_Failure _ -> print_endline "primitive failure"
     | Failure        -> print_endline "redefined failure"
==========

Hope this helps,
Julien Signoles
-- 
mailto:Julien.Signoles@lri.fr ; http://www.lri.fr/~signoles
"In theory, practice and theory are the same,
but in practice they are different" (Larry McVoy)