caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Preferred use of Invalid_argument and Failure
@ 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
  0 siblings, 2 replies; 11+ messages in thread
From: Michaël Le Barbier @ 2007-10-24  6:45 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-10-25  7:02 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-24  6:45 Preferred use of Invalid_argument and Failure 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 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).