Version française
Home     About     Download     Resources     Contact us    
Browse thread
Preferred use of Invalid_argument and Failure
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: michael.le_barbier@l...
Subject: Preferred use of Invalid_argument and Failure
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