Version française
Home     About     Download     Resources     Contact us    
Browse thread
FW: [Caml-list] newbie questions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Stefano Zacchiroli <zack@c...>
Subject: Re: FW: [Caml-list] newbie questions
On Wed, Aug 22, 2001 at 02:29:01PM -0400, Collin Monahan wrote:
> Well, here's a few things I don't understand right now.
> 
> try 
>  let chan = open_in "foobar"
> with Sys_error ->
>  print_string "error opening file\n";;
> 
> This doesn't work. I think it might be because the stuff in the first
> part doesn't evaluate to the same type as the stuff in the second part.
> I also wonder if it might have something to do with how in the
> documentation, lots of exceptions are described as, for example
> 	exception Stack_overflow
> but for Sys_error it says
> 	exception Sys_error of string

Exception are like others concrete type in OCaml the only difference is
that them are introduced with the keywork "exception".
When you define an exception you may define it with a variable number of
arguments; exception like "Stack_overflow" are exception with no
argument, exception like "Sys_error" are exception with one argument, in
particular "Sys_error" have one string argument (this is because the
same exception is used to report a lot of different errors).

In "try ... with" constructor, the "with" clause use a pattern matching
on the exception returned by the "try" clause that return an "Exception
of string" that is not matched by your pattern of the form "Exception".
You have to use something like:

try
  ...
with Sys_error ->
  print_string ...

Hope this helps ...

Cheers

-- 
Stefano "Zack" Zacchiroli <zack@cs.unibo.it> ICQ# 33538863
Home Page: http://www.students.cs.unibo.it/~zacchiro
Undergraduate student of Computer Science @ University of Bologna, Italy
                 - Information wants to be Open -
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr