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

exception Array_access of int

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)
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
better
for Ocaml to have built-in exceptions (not string literals) for things
of this importance?

best,

-- eliot

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to