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 BAA32735; Tue, 16 Apr 2002 01:00:19 +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 BAA12172 for ; Tue, 16 Apr 2002 01:00:18 +0200 (MET DST) Received: from speakeasy.org (shawnw-0.dsl.speakeasy.net [64.81.17.141]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g3FN0GD26858 for ; Tue, 16 Apr 2002 01:00:17 +0200 (MET DST) Received: (from shawnw@localhost) by speakeasy.org (8.10.1/8.10.1) id g3FMxGs29523 for caml-list@inria.fr; Mon, 15 Apr 2002 15:59:16 -0700 Date: Mon, 15 Apr 2002 15:59:15 -0700 From: Shawn Wagner To: caml-list@inria.fr Subject: Re: [Caml-list] Catching errors (Unix-Module) Message-ID: <20020415155915.K32318@speakeasy.org> Mail-Followup-To: caml-list@inria.fr References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from oliver@first.in-berlin.de on Mon, Apr 15, 2002 at 10:51:41PM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, Apr 15, 2002 at 10:51:41PM +0200, Oliver Bandel wrote: > Hello, > > I'm experimtnzing with the Unix-module and try to > cath Unix-errors. > > Look here: > > > ============================================= > oliver@first:/home/oliver > unix-top > Objective Caml version 3.01 > > # Unix.stat "/foo/bar";; > Uncaught exception: Unix.Unix_error (Unix.ENOENT, "stat", "/foo/bar"). > # > ============================================= > > How to handle such Errors? > > I tried this one: > > ============================================= > # try Unix.stat "/foo/bar" with Unix.Unix_error -> "shi...";; > Characters 30-45: > The constructor Unix.Unix_error expects 3 argument(s), > but is here applied to 0 argument(s) > # > ============================================= 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) You have to include all of the type constructor's arguments in an exception handler pattern (Using _ if you don't care about the actual value, i.e. Unix.Unix_error(code, _, _). > > What actions can I use here? > I may want to ignore some of those errors under some conditions, > but I also may want to handle them. You can catch any Unix_error with the above, or you can catch specific ones you're interested in like so: try blah with | Unix.Unix_error(Unix.ENOENT, func, arg) -> whatever | Unix.Unix_error(Unix.EACCES, func, arg) -> another error handler | Unix.Unix_error(code, func, arg) -> general Unix_error handler -- Shawn Wagner shawnw@speakeasy.org ------------------- 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