From: Shawn Wagner <shawnw@speakeasy.org>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Catching errors (Unix-Module)
Date: Mon, 15 Apr 2002 15:59:15 -0700 [thread overview]
Message-ID: <20020415155915.K32318@speakeasy.org> (raw)
In-Reply-To: <Pine.LNX.3.95.1020415223458.408A-100000@first.in-berlin.de>; from oliver@first.in-berlin.de on Mon, Apr 15, 2002 at 10:51:41PM +0200
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
next prev parent reply other threads:[~2002-04-15 23:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-15 20:51 Oliver Bandel
2002-04-15 22:59 ` Shawn Wagner [this message]
2002-04-16 13:04 ` Oliver Bandel
2002-04-16 13:22 ` Remi VANICAT
2002-04-16 13:56 ` Hendrik Tews
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=20020415155915.K32318@speakeasy.org \
--to=shawnw@speakeasy.org \
--cc=caml-list@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