From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA04272; Tue, 16 Apr 2002 15:22:34 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA11102 for ; Tue, 16 Apr 2002 15:22:33 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from mel-rto7.wanadoo.fr (smtp-out-7.wanadoo.fr [193.252.19.26]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g3GDMXb22461 for ; Tue, 16 Apr 2002 15:22:33 +0200 (MET DST) Received: from mel-rta7.wanadoo.fr (193.252.19.61) by mel-rto7.wanadoo.fr; 16 Apr 2002 15:22:33 +0200 Received: from debian (80.8.76.40) by mel-rta7.wanadoo.fr (6.5.007) id 3CBAA820000616C4 for caml-list@inria.fr; Tue, 16 Apr 2002 15:22:33 +0200 Received: from moi by debian with local (Exim 3.35 #1 (Debian)) id 16xSus-00019Z-00 for ; Tue, 16 Apr 2002 15:22:38 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] Catching errors (Unix-Module) References: From: Remi VANICAT Date: 16 Apr 2002 15:22:38 +0200 In-Reply-To: Message-ID: <87hembbwwx.dlv@wanadoo.fr> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Oliver Bandel writes: > Hello, > > On Mon, 15 Apr 2002, Shawn Wagner wrote: > > > try > > Unix.stat "/foo/bar" > > with > > | Unix.Unix_error (code, func, file) -> > > Printf.fprintf stderr "Couldn't %s '%s': %s!\n" > > func file (Unix.error_message code) > > > OK, let's try it: > ============================================ > oliver@first:/home/oliver > unix-top > Objective Caml version 3.01 > > # > try > Unix.stat "/foo/bar" > with > | Unix.Unix_error (code, func, file) -> > Printf.fprintf stderr "Couldn't %s '%s': %s!\n" > func file (Unix.error_message code) > > ;; > Characters 74-161: > This expression has type unit but is here used with type Unix.stats Your expression have a type, an which ever case happen, it must return a value of the same type (here Unix.stats), then Printf.fprintf doesn't return something of type Unix.stats, an so this code doesn't work. Something like : try Some (Unix.stat "/foo/bar") with | Unix.Unix_error (code, func, file) -> Printf.fprintf stderr "Couldn't %s '%s': %s!\n" func file (Unix.error_message code); None will work, as try Unix.stat "/foo/bar" with | Unix.Unix_error (code, func, file) as exn -> Printf.fprintf stderr "Couldn't %s '%s': %s!\n" func file (Unix.error_message code) raise exn (but in the latter case, the exception is reraised after the message have been printed, it may not be what you want). -- Rémi Vanicat vanicat@labri.u-bordeaux.fr http://dept-info.labri.u-bordeaux.fr/~vanicat ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners