caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
To: Philippe Veber <philippe.veber@gmail.com>
Cc: Ben Millwood <bmillwood@janestreet.com>,
	Romain Bardou <romain.bardou@inria.fr>,
	caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Uncaught exceptions in function type.
Date: Tue, 27 May 2014 23:16:18 +0200	[thread overview]
Message-ID: <0735CE04495C45A994EE280663B61062@erratique.ch> (raw)
In-Reply-To: <CAOOOohTGzRtDSuro998UMQOdvivL8E6C7Znnu=97+g8iHTUQ1A@mail.gmail.com>



Le mardi, 27 mai 2014 à 08:52, Philippe Veber a écrit :

> - I observed in many libraries (including Xmlm) that people tend to define custom exceptions to signal parsing errors. According to the rules you provide, parsers should return variants, right?

Yes, I was unexeperienced.  Also I didn’t understand that the world was asynchronous at that time. See jsonm for a more sensitive interface.

> - as Ben noted earlier, I think point 2 would better be formulated as errors that can virtually appear anywhere and/or a programmer cannot do much about (as you say)
> - The adjective "exceptional" is a bit misleading IMO, in particular I guess it should not be understood as "not frequent". Rare failures can be very harmful and should be given extra-care since they are not easy to provoke and debug. Did you mean more like "very abnormal" and so difficult to recover?

Well all what you mention seems exceptional to me (at least I wouldn’t like to work with an API that allows errors to virtually happen everywhere on a regular basis)… But feel free to call that differently.  
  
> - Another criterion I like is that if checking the precondition of a function f basically amounts (in terms of complexity/algorithm) to calling f, then f shouldn't raise an exception for this precondition. If the precondition is difficult to check, a user is likely not to check it:
> - List.find assumes the searched element is in the list, but checking that is precisely what the function is about.

Yes, note that finding things in datastructures is pretty clear API wise. Usually there are two cases 1) the programmer doesn’t if the item is in the datastructure 2) the programmer knows it’s in there and doesn’t want to be annoyed. This leads to

1) val find : t -> key -> value option
2) val get : t -> key -> value (and raises Invalid_argument if the thing is not in there).  
  
> Having no experience on large projects, it is not clear to me why exceptions are considered so dangerous.  

If you don’t/forget to catch the exception at the right place it disrupts your whole call stack, which means that it breaks any invariants a correct excecution of your call stack was supposed to maintain. Which means that your program state is completely broken and you have to exit 1, hoping that you didn’t partially (invariant wise) persist anything to disk/network meanwhile.

Best,

Daniel






  parent reply	other threads:[~2014-05-27 21:16 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-26 14:23 Philippe Veber
2014-05-26 14:56 ` Romain Bardou
2014-05-26 15:13   ` Ben Millwood
2014-05-26 16:02     ` Philippe Veber
2014-05-26 16:34       ` Daniel Bünzli
2014-05-27  6:52         ` Philippe Veber
2014-05-27  8:42           ` Ben Millwood
2014-05-27 10:05             ` Goswin von Brederlow
2014-05-27 10:36               ` Ben Millwood
2014-05-27 11:24                 ` Yaron Minsky
2014-05-27 21:42             ` Daniel Bünzli
2014-05-27 21:16           ` Daniel Bünzli [this message]
2014-06-02  8:38             ` Goswin von Brederlow
2014-05-27  8:49         ` Goswin von Brederlow
2014-05-27  8:56           ` David House
2014-05-27 21:39           ` Daniel Bünzli
2014-06-02  8:31             ` Goswin von Brederlow
2014-05-27  9:25         ` Nicolas Boulay
2014-05-27 21:51           ` Daniel Bünzli
2014-05-30 18:03         ` Florian Weimer
2014-05-31 11:26           ` Daniel Bünzli
2014-06-02  8:43             ` Goswin von Brederlow
2014-05-26 15:25   ` Philippe Veber
2014-05-27  9:28     ` Goswin von Brederlow
2014-05-27  9:38       ` Romain Bardou
2014-05-26 15:33 ` Thomas Blanc
2014-05-26 16:04   ` Philippe Veber
2014-05-26 15:33 ` Gabriel Scherer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0735CE04495C45A994EE280663B61062@erratique.ch \
    --to=daniel.buenzli@erratique.ch \
    --cc=bmillwood@janestreet.com \
    --cc=caml-list@inria.fr \
    --cc=philippe.veber@gmail.com \
    --cc=romain.bardou@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).