caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Bünzli Daniel" <daniel.buenzli@erratique.ch>
To: "Till Varoquaux" <till.varoquaux@gmail.com>
Cc: "caml-list List" <caml-list@inria.fr>
Subject: Re: [Caml-list] [OSR] Exceptionless error management
Date: Thu, 31 Jan 2008 12:01:33 +0100	[thread overview]
Message-ID: <0640C30E-07B5-4885-AC38-671755BB79AA@erratique.ch> (raw)
In-Reply-To: <9d3ec8300801310157r77b86fc0k80f40b1df36091c2@mail.gmail.com>

Le 31 janv. 08 à 10:57, Till Varoquaux a écrit :

> My cocan account is not created yet soo I will answer here:

I think it is better to discuss on the list.

> _ In the thread you are pointing to Xavier did not say using
> exceptions was a mistake, he said the Failure exception (such as
> int_of_string) was legacy code and not great.

Right, corrected.

> _ Allowing Invalid_argument seems a little to hardcore. When doing
> system programming for instance there is an incredible range of
> exceptional events that can happen, you are definitly not going to
> handle all of them (or are you?) so you will need to let them trickle
> up. This will eventually require using something akin to an error
> monad and some awfull mangling with polymorpic variants.

This OSR is mainly targeted at reusable modules and it says nothing  
about clients of the module. Clients are allowed to define their own  
exceptions to propagate the error up. The contract of a conforming  
module is that it won't interfere with the client's control flow as  
long as it behaves correctly.

> _Exceptions are terse. Suppose Map.find returned an option type (and
> this seems a sensible choice). If you were in a place where not being
> in the map really was an exceptional event you'd need to unbox and do
> some error handling for every lookup (and since you do not want to
> raise an exception I must wonder what you would do).

They are terse because they are implicit and I don't like this. For me  
either not being in the map can happen and then you have to deal with  
it at each call because of program correctness either you know, e.g.  
by construction, that not being in the map cannot happen. In the  
latter case I would define the following local function :

let find map k = match Map.find map k with Some v -> v | None ->  
assert false

> _For functions like find... declare two functions: one that boxes it's
> return value (i.e val input_line : in_channel -> string option) and
> another that raises an exception (i.e val input_line_exn : in_channel
> -> string).

Requiring this clutters apis and is more work for the module  
developer. If you want a function that raises you can define your own  
local function as suggested above.

Best,

Daniel

  reply	other threads:[~2008-01-31 11:01 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-31  8:55 Bünzli Daniel
2008-01-31  9:57 ` [Caml-list] " Till Varoquaux
2008-01-31 11:01   ` Bünzli Daniel [this message]
2008-01-31 14:09     ` Andrej Bauer
2008-01-31 14:16       ` Michael Ekstrand
2008-01-31 19:28         ` David Teller
2008-01-31 19:59           ` Michael Ekstrand
2008-01-31 20:05           ` blue storm
2008-01-31 20:03       ` Bünzli Daniel
2008-01-31 20:25         ` David Teller
2008-01-31 20:40           ` David Teller
2008-01-31 21:16           ` Bünzli Daniel
2008-01-31 21:31             ` David Teller
2008-01-31 21:35           ` Jon Harrop
2008-01-31 22:01           ` Christophe Raffalli
2008-02-01  7:27         ` Michaël Grünewald
2008-02-01  7:47           ` Bünzli Daniel
2008-02-01 10:50             ` Till Varoquaux
2008-02-01 11:31               ` Bünzli Daniel
2008-02-01 15:59                 ` Vincent Hanquez
2008-02-01 18:37                   ` Bünzli Daniel
2008-02-01 19:43                     ` Vincent Hanquez
2008-02-01 16:04                 ` David Allsopp
2008-02-01  8:31 ` David Teller
2008-02-01 12:19   ` Yaron Minsky
2008-02-05 10:00 ` David Teller
2008-02-05 10:12   ` Vincent Hanquez
2008-02-05 10:26     ` Bünzli Daniel
2008-02-05 11:06       ` Vincent Hanquez
2008-02-05 13:46         ` Jon Harrop
2008-02-05 11:36       ` Frédéric van der Plancke
2008-02-06  8:45       ` Michaël Grünewald
2008-02-08 13:09         ` Bünzli Daniel
2008-02-05 14:12     ` David Teller
2008-02-11  8:12 ` David Teller
2008-02-11  9:09   ` Bünzli Daniel

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=0640C30E-07B5-4885-AC38-671755BB79AA@erratique.ch \
    --to=daniel.buenzli@erratique.ch \
    --cc=caml-list@inria.fr \
    --cc=till.varoquaux@gmail.com \
    /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).