caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Michaël Le Barbier" <michael.le_barbier@laposte.net>
To: Xavier Leroy <Xavier.Leroy@inria.fr>
Cc: "Michaël Le Barbier" <michael.le_barbier@laposte.net>,
	caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Preferred use of Invalid_argument and Failure
Date: Thu, 25 Oct 2007 09:07:03 +0200	[thread overview]
Message-ID: <86abq7ad0o.fsf@Llea.celt.neu> (raw)
In-Reply-To: <471EFD20.5010303@inria.fr> (Xavier Leroy's message of "Wed\, 24 Oct 2007 10\:06\:56 +0200")

Xavier Leroy <Xavier.Leroy@inria.fr> writes:

> The convention that the standard library tries to follow is this.
>
> Invalid_argument is very much like a failed assertion: it indicates
> that something is wrong in the program itself, i.e. negative character
> positions in string functions.  Most programs will not catch
> Invalid_argument, treating as a fatal error.  Others will catch it,
> but only to enter a piece of generic "recover from unexpected error"
> code.
>
> Failure, on the other hand, signals errors that can happen in normal
> runs of the code.  For instance, you're converting a user-provided
> string to a number, and the string does not represent a number.  It is
> expected that the client code catches Failure and recovers gracefully,
> e.g. by asking for the number again, or producing a precise "syntax
> error" message.
>
> I recommend the use of Invalid_argument to report "should never
> happen" conditions at the boundary between library functions and user
> code.  On the other hand, the "Failure" exception is a bit of a legacy
> from earlier designs (Caml Light and even the original LeLisp-based
> Caml), and often is not the best way to report "normal error"
> conditions: instead, you could consider defining your own exceptions
> as Alain suggested, or even have your functions return "option" types
> instead of raising exceptions.

Thank you very much for your description of the error reporting scheme
used in the standard library, you made the things very clear.

Following your joined advices with Alain Frisch, I will rethink error
reporting scheme in that library to provide more accurate error
diagnostics. Accurate errors are clearly more useful than vague ones.

I suppose the ``right thing to do'' depends greatly of the application
type. Specifically, I am working on a program that do scientific
computations, and I am very interesting in getting a precise
description of parameters that crashed my program: throwing exception
seems a convenient way to provide this feedback.

Thanks again to all contributors for their valuable advices.
-- 
Cheers,
Michaël


      parent reply	other threads:[~2007-10-25  7:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-24  6:45 Michaël Le Barbier
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 [this message]

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=86abq7ad0o.fsf@Llea.celt.neu \
    --to=michael.le_barbier@laposte.net \
    --cc=Xavier.Leroy@inria.fr \
    --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).