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 UAA02359; Fri, 16 Jul 2004 20:54:01 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA02361 for ; Fri, 16 Jul 2004 20:54:00 +0200 (MET DST) Received: from swordfish.cs.caltech.edu (swordfish.cs.caltech.edu [131.215.44.124]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i6GIrwEV025037 for ; Fri, 16 Jul 2004 20:53:59 +0200 Received: from [192.168.1.100] (charter-242-009.caltech.edu [131.215.242.9]) by swordfish.cs.caltech.edu (Postfix) with ESMTP id 44FF5DF2F6; Fri, 16 Jul 2004 11:53:57 -0700 (PDT) Message-ID: <40F82445.3070307@cs.caltech.edu> Date: Fri, 16 Jul 2004 11:53:57 -0700 From: Aleksey Nogin Organization: California Institute of Technology, Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8a2) Gecko/20040607 X-Accept-Language: ru, en-us, en MIME-Version: 1.0 To: Radu Grigore Cc: caml-list@inria.fr Subject: Re: [Caml-list] assertions or exceptions? References: <7f8e92aa04071501035091cbe9@mail.gmail.com> <20040715101826.GA10062@redhat.com> <7f8e92aa04071505495315454@mail.gmail.com> <20040715133359.GA13273@redhat.com> <7f8e92aa040715065823a44bdf@mail.gmail.com> In-Reply-To: <7f8e92aa040715065823a44bdf@mail.gmail.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 40F82446.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 openfile:01 implemented:01 openfile:01 626:99 invoke:01 linked:01 assertions:01 caltech:01 caltech:01 catching:02 wrote:03 let:04 boolean:04 exceptions:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On 15.07.2004 06:58, Radu Grigore wrote: >>let valid_hostname r = >> try ignore (Request.hostname r); true with Not_found -> false > > > Maybe Request.hostname is a bad example. In general you can provide a > query that is more efficient than actually trying to do it. The > example to which I linked in the previous email was about an OpenFile > method that can throw FileNotFound paired with FileExists that returns > a boolean. I'd bet FileExists is not implemented in terms of OpenFile. Actually your FileExists/OpenFile case is a perfect example of why you need exceptions anyway - even if you test a file with FileExists, by the time you invoke OpenFile, the file might be already gone! So unless you want to open yourself to race conditions, the only safe way is to go ahead and use OpenFile, catching any exceptions it could raise. -- Aleksey Nogin Home Page: http://nogin.org/ E-Mail: nogin@cs.caltech.edu (office), aleksey@nogin.org (personal) Office: Jorgensen 70, tel: (626) 395-2907 ------------------- 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