caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Stefano Zacchiroli <zack@cs.unibo.it>
To: Collin Monahan <cmonahan@fame.com>
Cc: caml-list@inria.fr
Subject: Re: FW: [Caml-list] newbie questions
Date: Fri, 24 Aug 2001 08:51:56 +0200	[thread overview]
Message-ID: <20010824085156.A757@cs.unibo.it> (raw)
In-Reply-To: <001501c12b38$50c3d9a0$f54258c0@CONSULTING2000P>

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


  reply	other threads:[~2001-08-24  6:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-22 18:29 Collin Monahan
2001-08-24  6:51 ` Stefano Zacchiroli [this message]
2001-08-24  7:31   ` David Mentre
2001-08-24 10:57     ` Stefano Zacchiroli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010824085156.A757@cs.unibo.it \
    --to=zack@cs.unibo.it \
    --cc=caml-list@inria.fr \
    --cc=cmonahan@fame.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).