Version française
Home     About     Download     Resources     Contact us    
Browse thread
Preferred use of Invalid_argument and Failure
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Yaron Minsky <yminsky@c...>
Subject: Re: [Caml-list] Preferred use of Invalid_argument and Failure
On 10/24/07, Xavier Leroy <Xavier.Leroy@inria.fr> wrote:
>
>
> I recommend the use of Invalid_argument to report "should never
> happen" conditions at the boundary between library functions and user
> code.  On the other hand, the "Failure" exception is a bit of a legacy
> from earlier designs (Caml Light and even the original LeLisp-based
> Caml), and often is not the best way to report "normal error"
> conditions: instead, you could consider defining your own exceptions
> as Alain suggested, or even have your functions return "option" types
> instead of raising exceptions.


Where I work, we have come to dearly love the practice of returning
polymorphic variants with explicit  variants for various "normal" error
cases.  This is pretty lightweight, and is also very clear and explicit,
both when looking at the function signature and at the call point.

y