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 UAA28228; Wed, 7 Apr 2004 20:04:17 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA28208 for ; Wed, 7 Apr 2004 20:04:16 +0200 (MET DST) Received: from rabelais.socialtools.net (rabelais.socialtools.net [81.2.94.243]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i37I4EYM030535 for ; Wed, 7 Apr 2004 20:04:15 +0200 Received: by rabelais.socialtools.net (Postfix, from userid 108) id B87772332F; Wed, 7 Apr 2004 19:04:14 +0100 (BST) Received: from socialtools.net (chaucer.socialtools.net [81.2.94.242]) by rabelais.socialtools.net (Postfix) with ESMTP id 91A37232DF; Wed, 7 Apr 2004 19:04:13 +0100 (BST) Message-ID: <40744295.8030001@socialtools.net> Date: Wed, 07 Apr 2004 19:04:05 +0100 From: Benjamin Geer User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: en-gb, en, fr, it MIME-Version: 1.0 To: Richard Jones Cc: caml-list Subject: Re: [Caml-list] Function forward declaration? References: <60532B15DF92FD4693AA89B2F7E01D8F013F29EC@tmex02> <00cf01c41bd6$391b53a0$0203a8c0@hoedic> <20040406175320.GA19840@redhat.com> <1081279717.16531.6.camel@qrnik> <002901c41c65$b53e4c50$19b0e152@warp> <1081345936.19232.579.camel@pelican> <20040407141519.GA6618@redhat.com> <1081353080.19232.678.camel@pelican> <20040407164122.GA9247@redhat.com> In-Reply-To: <20040407164122.GA9247@redhat.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on rabelais.socialtools.net X-Spam-Status: No, hits=-4.9 required=5.0 tests=BAYES_00 autolearn=ham version=2.63 X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 permissions:01 dbh:99 userid:99 permissions:01 userid:99 failwith:01 dbh:99 failwith:01 separates:01 generic:01 gui:01 gtk:01 concise:01 wrote:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 104 Richard Jones wrote: > This is the sort of thing which I'd like to write. It looks as if using exceptions would simplify your example. If your check_permissions and find_resource functions threw exceptions containing error messages (e.g. Failure), you could write: let run dbh q userid = try check_permissions userid; let query = q#param "query" in if is_empty query then failwith "Please enter a query" else let resource = try find_resource dbh query with Not_found -> failwith "That resource doesn't exist in the database" in (* do some work *); StdPages.ok q "OK, your query was executed" with Failure msg -> StdPages.error q msg ;; Besides being more concise, I think this is an improvement because it separates the identification of an error with the way the error is reported. This means that if someday you want to change the way you handle errors, you have less code to change; in the version above, there is only one line of code that knows about StdPages.error. (It would perhaps be even better to wrap the calls to StdPages.ok and StdPages.error in more generic report_success and report_error functions, so that if someday you changed your mind about having a single standard error page, or if you decided to implement a completely different sort of GUI, e.g. using GTK+, you wouldn't have to change the 'run' function at all.) Ben ------------------- 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