Out of bounds errors raise Invalid_argument. In OCaml these exceptions are not meant to be catched, they denote a programming error.
Thanks for the precision. When you say these exceptions denote a programming error do you mean that a program should never throw such exception and that it is the duty of the caller to check that the callee will never throw an
Invalid_argument exception ? Is this denotation a tacit convention between OCaml programmer ?
I tried to compile my code with
-unsafe-string. In the first case I got an uncatch
Invalid_argument exception but with
String.sub : I suppose it came from the use in
decompose but I don’t understand why. In the second case there is no problem. In both cases, I never saw a segfault.
I changed the
next_index function with :
let next_index s offset =
let len = String.length s in
let rec loop quit idx =
if idx >= len then idx
else match is_lower s.[idx] with
| true -> loop true (succ idx)
| false when quit-> idx
| _ -> loop false (succ idx)
in loop false offset
and it works fine with both