caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Exception Unix_error problem in toplevel
@ 2007-02-02  1:10 Bob Williams
  2007-02-02 12:08 ` [Caml-list] " ls-ocaml-developer-2006
  2007-02-02 13:13 ` Vu Ngoc San
  0 siblings, 2 replies; 11+ messages in thread
From: Bob Williams @ 2007-02-02  1:10 UTC (permalink / raw)
  To: caml-list

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?


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-02-06  7:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-02  1:10 Exception Unix_error problem in toplevel Bob Williams
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

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).