caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Dave Benjamin <dave@ramenlabs.com>
To: tmp123@menta.net
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] try with
Date: Sun, 5 Aug 2007 10:23:12 -0500 (CDT)	[thread overview]
Message-ID: <Pine.LNX.4.63.0708051018280.7554@tenhost.net> (raw)
In-Reply-To: <46B5ECE4.2050208@menta.net>

On Sun, 5 Aug 2007, tmp123@menta.net wrote:

> Sorry for an easy question about exceptions:
>
> If in a code like:
>
> let v1 = f1 () in
> f2 v1
>
> I like to handle in a different way an exception (like Not_found) 
> produced inside f1 of the same one produced in f2 (or even not treat the 
> one produced in f2), which one is a correct way to write the code?

One way (besides the exception technique you posted) is to convert the 
exception to an option or other variant:

let maybe_v1 = try Some (f1 ()) with Not_found -> None in
match maybe_v1 with
   | Some v1 -> f2 v1
   | None -> handle_f1_exception ()

Also see the following page for a "let try" syntax extension:

http://martin.jambon.free.fr/extend-ocaml-syntax.html#lettry


  reply	other threads:[~2007-08-05 15:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-05 15:29 tmp123
2007-08-05 15:23 ` Dave Benjamin [this message]
2007-08-05 15:50 ` [Caml-list] " skaller

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=Pine.LNX.4.63.0708051018280.7554@tenhost.net \
    --to=dave@ramenlabs.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=tmp123@menta.net \
    /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).