Version française
Home     About     Download     Resources     Contact us    
Browse thread
Question about try.. with
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Question about try.. with
From: christian konrad <konrad@in.tum.de>

> I'm doing that:
> 
> let _ =
>   try
>    let infile = open_in !filename in
>    let rec readIn () =
>       try
>          (input_line infile) ^ readIn();
>       with ee -> "";
>    in
>     print_string(readIn () );
>    "good";
>   with e -> "";;
> 
> So why don't I get any output at all? Doesn't "with" erease the raised 
> Exception?

Because you assume wrongly that input_line will be called before the
recursive call to readIn. Nothing in the ocaml specification says so
(evaluation order is left undefined.) In practice the rightmost call
is done first, which is the recursive call here, but you shouldn't
depend on it either.
By the way, it is a bad idea to catch all exceptions. ee should be
End_of_file and e should be Sys_error _.

Jacques Garrigue