Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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  =
     try
          [||].(i)
     with 
       Invalid_argument _ -> raise (Array_access i)

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

Cheers,
ChriS