From: Bob Williams <a6a37331@telus.net>
To: caml-list@yquem.inria.fr
Subject: Exception Unix_error problem in toplevel
Date: Thu, 1 Feb 2007 17:10:14 -0800 [thread overview]
Message-ID: <20070202011014.GA27655@telus.net> (raw)
Summary of problem: If you call a function from a script, that
function will raise and catch Unix_error properly. However, if you
call the same function interactively from an OCaml toplevel, the
function will see an exception but will think it is *not* Unix_error.
A demonstration appears below.
OCaml version : 3.09.2-9
Distribution : Debian Linux for i386
Linux kernel : 2.6.18
Here is file "bug.ml":
open Unix
open Printf
let delete_file () =
try
unlink "no_such"
with
| Unix_error (_, _, _) -> Printf.eprintf "Unix error.\n%!"
| _ -> Printf.eprintf "Some other error.\n%!"
Here is the script "run.ml":
Bug.delete_file ()
The following works properly:
$ ocamlc -c bug.ml
$ ocaml unix.cma bug.cmo run.ml
Unix error.
The output "Unix error" is correct because the file named "no_such"
does not exist. (By the way, "unix.cma" is OCaml's standard Unix
library.)
Now I omit the script "run.ml" from the ocaml command line and call
Bug.delete_file interactively, as follows:
$ ocaml unix.cma bug.cmo
Objective Caml version 3.09.2
# Bug.delete_file ();;
Some other error.
The output should be the same as for the first example, but it isn't.
Strange, isn't it?
next reply other threads:[~2007-02-02 1:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-02 1:10 Bob Williams [this message]
2007-02-02 12:08 ` [Caml-list] " ls-ocaml-developer-2006
2007-02-02 13:21 ` Luc Maranget
2007-02-03 2:29 ` Bob Williams
2007-02-03 9:57 ` Gabriel Kerneis
2007-02-04 0:34 ` Bob Williams
2007-02-03 13:48 ` ls-ocaml-developer-2006
2007-02-04 0:46 ` Bob Williams
2007-02-04 10:46 ` ls-ocaml-developer-2006
2007-02-06 7:20 ` Bob Williams
2007-02-02 13:13 ` Vu Ngoc San
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=20070202011014.GA27655@telus.net \
--to=a6a37331@telus.net \
--cc=caml-list@yquem.inria.fr \
/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).