caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: michael.le_barbier@laposte.net (Michaël Le Barbier)
To: caml-list@yquem.inria.fr
Subject: Preferred use of Invalid_argument and Failure
Date: Wed, 24 Oct 2007 08:45:41 +0200	[thread overview]
Message-ID: <867ildqacq.fsf@Llea.celt.neu> (raw)

Hi,

I am working on a library, I want the interfaces to look like standard
library modules interfaces. From the standard library modules, it is
usually possible to tell if fonction should be called `of'_string,
`from'_string, etc. Considering exceptions, the situation is not so
clear to me, and I would be glad to get a piece of advice or your
feelings to help me towards a consistant use of these two exceptions.


Small discussion:

Let's quote the manual (release 3.09):

  exception Invalid_argument of string

    Exception raised by library functions to signal that the given
    arguments do not make sense.

  exception Failure of string

    Exception raised by library functions to signal that they are
    undefined on the given arguments.


It seems to me that Invalid_argument is a sort of specialisation of
Failure. A general rule that emerges from standard library modules is
that:
  * when a function can tell a priori it's undefined on its arguments
    (exemple: String.blit) it should raise Invalid_argument;
  * when a function must try to compute an answer before it turns out
    there is no answer, it raises Failure (let's say you try to solve
    a singular system).
However this general rule is not strictly followed by standard library
modules. Again, I would be glad to get advices of discipline in using
theses two exceptions. What works for you?
-- 
Cheers,
Michaël


             reply	other threads:[~2007-10-24  6:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-24  6:45 Michaël Le Barbier [this message]
2007-10-24  7:06 ` [Caml-list] " Alain Frisch
2007-10-24  8:06 ` Xavier Leroy
2007-10-24 11:05   ` Yaron Minsky
2007-10-24 11:30     ` Joel Reymont
2007-10-24 13:15       ` Yaron Minsky
2007-10-24 13:22         ` Daniel Bünzli
2007-10-24 14:45           ` Jon Harrop
2007-10-24 15:10           ` Richard Jones
2007-10-24 14:44         ` Jon Harrop
2007-10-25  7:07   ` Michaël Le Barbier

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=867ildqacq.fsf@Llea.celt.neu \
    --to=michael.le_barbier@laposte.net \
    --cc=caml-list@yquem.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).