English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Wanted: your feedback on the hierarchy of OCaml Batteries Included
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-11-21 (09:53)
From: Christophe TROESTLER <Christophe.Troestler+ocaml@u...>
Subject: Re: [Caml-list] Stability of exceptions
On Thu, 20 Nov 2008 21:56:32 -0500, Eliot Handelman wrote:
> let test i  =
>    try
>         [||].(i)
>    with 
>      Invalid_argument "index out of bounds" -> raise (Array_access i)
> The problem is that this test is dependent on a literal string match of
> "index out of bounds." If
> I accidentally write something like "index  out out bounds" (an extra
> space between index & out)

These strings are for user information, you should write

  let test i  =
       Invalid_argument _ -> raise (Array_access i)

IMHO, in this case, you should rather make sure you do not perform
accesses outside the array bounds.