Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] assertions or exceptions?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-07-16 (18:54)
From: Aleksey Nogin <nogin@c...>
Subject: Re: [Caml-list] assertions or exceptions?
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:
E-Mail: (office), (personal)
Office: Jorgensen 70, tel: (626) 395-2907

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: