Re: Exceptions vs NaN/NaI
On 2012-05-07 17:23:05 +0100, John Pryce wrote:
> P1788
>
> On 18 Apr 2012, at 13:40, Vincent Lefevre wrote:
> > Dmitry wrote:
> >> There are a few common ways to signal a failure in programming anguages:
> >> 1) Set a global/thread-local flag like "errno";
> >> 2) Return specifal value like NaI or NaN;
> >> 3) Throw a language exception (like in C++ or in Java).
> >>
> >> As far as I understand, the draft of the standard recommends(requires) (2).
> ...
> >> However, shouldn't the P1788 be flexible enough to allow
> >> both level 2 operations that signal by (2)
> >> and level 2 operations that signal by (3) ?
> >
> > I think that (2) should be mandatory, but (3) can be allowed if
> > the user requests it ((3) is not possible in all languages).
>
> Surely (3) is *allowed* as long as the standard doesn't forbid it,
> which I see no reason to do. Are you suggesting the standard should
> do something stronger than *allow*, e.g. *recommend* that
> implementations provide (3)?
I don't think that (3) is allowed. For instance in Motion 30.02 on
constructors:
The decorated interval constructors nums2interval(l,u),
text2interval(t), empty(), entire() are defined as follows.
If the value xx of the corresponding bare interval constructor
is defined, then the decorated interval constructor is said to
succeed, and returns (xx,d) where d is appropriate, in the
decoration system, for a new interval with the value xx.
Otherwise it fails, and returns a NaI as determined by the
decoration system.
So, in case of failure, one would get a NaI, i.e. (2). A language
exception is not allowed currently. However a later motion could
specify that a language exception (or some other alternate way to
signal an error, language-defined) is allowed, as an optional
feature, whenever a NaI is returned with the default behavior.
--
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)