From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=MAILTO_TO_SPAM_ADDR autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 6C950BC69 for ; Sun, 5 Aug 2007 17:49:47 +0200 (CEST) Received: from tenhost.net (tenhost.net [64.246.28.52]) by concorde.inria.fr (8.13.6/8.13.6) with SMTP id l75Fnj7R004528 for ; Sun, 5 Aug 2007 17:49:46 +0200 Received: (qmail 18693 invoked by uid 502); 5 Aug 2007 10:23:12 -0500 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 5 Aug 2007 10:23:12 -0500 Date: Sun, 5 Aug 2007 10:23:12 -0500 (CDT) From: Dave Benjamin X-X-Sender: ramen@tenhost.net To: tmp123@menta.net Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] try with In-Reply-To: <46B5ECE4.2050208@menta.net> Message-ID: References: <46B5ECE4.2050208@menta.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at concorde with ID 46B5F199.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; syntax:01 2007,:98 wrote:01 exception:01 exception:01 caml-list:01 exceptions:01 benjamin:01 jambon:01 variant:02 match:02 let:03 let:03 tmp:05 extension:06 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