Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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 (02:56)
From: Eliot Handelman <eliot@c...>
Subject: Stability of exceptions

In order to catch array access violations,  it seems necessary to do
something like this:

exception Array_access of int

let test i  =
     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)
then, of course, the above code will not raise Array_access, and indeed
it may be quite hard for me to
discover what went wrong. This seems inconsistent with the idea of
strong typing.

Is there some guarantee in the language that in future releases, the
"index out of bounds" message will remain
exactly what it currently is? My problem is not confined to this
particular case, but rather
with all  exceptions that have to be matched on string literals, in
particular because I'm a
rather poor typist.  What's the common practice here? Would it not be
for Ocaml to have built-in exceptions (not string literals) for things
of this importance?


-- eliot