From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 0633E7F8F2 for ; Mon, 2 Jun 2014 10:31:38 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=pra; client-ip=212.227.17.11; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=mailfrom; client-ip=212.227.17.11; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.web.de) identity=helo; client-ip=212.227.17.11; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="postmaster@mout.web.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoMBANg1jFPU4xELnGdsb2JhbABZw3aDDwGBEhYOAQEBAQEGDQkJFCiCJQEBBScLAVYLGAklDwUoiGEBGM1UH4Y8F4kzhGw6FoMVgRUBA5l/hlcSj38 X-IPAS-Result: AoMBANg1jFPU4xELnGdsb2JhbABZw3aDDwGBEhYOAQEBAQEGDQkJFCiCJQEBBScLAVYLGAklDwUoiGEBGM1UH4Y8F4kzhGw6FoMVgRUBA5l/hlcSj38 X-IronPort-AV: E=Sophos;i="4.98,955,1392159600"; d="scan'208";a="64985830" Received: from mout.web.de ([212.227.17.11]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 02 Jun 2014 10:31:37 +0200 Received: from frosties.localnet ([78.43.112.61]) by smtp.web.de (mrweb001) with ESMTPSA (Nemesis) id 0MFLMa-1X3QL62UFg-00EKfj for ; Mon, 02 Jun 2014 10:31:36 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.82) (envelope-from ) id 1WrNeZ-00004r-72 for caml-list@inria.fr; Mon, 02 Jun 2014 10:31:35 +0200 Date: Mon, 2 Jun 2014 10:31:35 +0200 From: Goswin von Brederlow To: caml-list@inria.fr Message-ID: <20140602083135.GA32010@frosties> References: <53835610.9050609@inria.fr> <53B801AD6F5B4BFBA0DA2A69D8775497@erratique.ch> <20140527084954.GA15848@frosties> <244F680EFB184D4693C2F7AAC6889EAE@erratique.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <244F680EFB184D4693C2F7AAC6889EAE@erratique.ch> User-Agent: Mutt/1.5.23 (2014-03-12) X-Provags-ID: V03:K0:UqOj2/iMAxvG0b4hLqpOqNALUTdCHcqHArAL4miYmH80jhAhhig +PADSl0LyhuvrRyfQ1DbSKCbLPJDsqy5Ffin1Q2c179CG6cWGA7zmcdOqUIm9zOAFW8aHCS SVEcyVFIHF7GZfdjjA1uZYennZUz7L0NhvrQK4FTTGgeExsiCqIcMO95J1Go3YomBkWptzq MbvzA+49IBc5XBDXnPIzQ== Subject: Re: [Caml-list] Uncaught exceptions in function type. On Tue, May 27, 2014 at 11:39:20PM +0200, Daniel Bünzli wrote: > Le mardi, 27 mai 2014 à 10:49, Goswin von Brederlow a écrit : > > Sometimes arguments are computed and suddenly exceed aceptable > > parameters. E.g. the user specifies a data file that needs to be read > > into a string. If the file is too large you get Invalid_argument. > > Programms can catch and handle such cases, at least to the point of > > giving a good error message. > > > Bad api. Neither exceptional error, neither programming error, *should* not raise Invalid_argument, of course you???ll have to handle it but don't forget to send hate emails to the API designer. > > > That is a matter of taste and with recursions in the mix exceptions > > can be a great way to abort the recursion while keeping the code flow > > simple. They also allow you to use things like List.fold_left and > > abort early. > > It???s not a matter of taste. What you are describing here is usage of exceptions by a programmer that wants to shoot himself in the foot. Libraries themselves should never disrupt the control flow of clients. > > Best, > > Daniel Who said anything about disrupting the codeflow of clients? The use case is like exception Result of int let find_less_than x list = try List.iter (fun y -> if x > y then raise (Result y)) list; None with Result y -> Some y # find_less_than 10 [100; 23; 3; 42; 17];; - : int option = Some 3 You hrow the exception internally and catch it internally. Nothing of the clients gets disruppted. Obviously this is a constructed simplistic example. But in more complex code an exception can be far more readable than 50 ifs and checks of None/Some all over the place. MfG Goswin