Thread Links Date Links
Thread Prev Thread Next Thread Index Date Prev Date Next Date Index

Exceptions vs NaN/NaI



It's a good point about trowing an exception.

Some constructors and numeric functions are undefined at Level 1 for some argument values.
Level 2 constructors/functions shall signal failure for such argument values.

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).
I don't like (1) too.
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) ?

  -Dima 


----- Исходное сообщение -----
От: eliasen@xxxxxxxxxxxxxx
Кому: stds-1788@xxxxxxxxxxxxxxxxx
Отправленные: Среда, 18 Апрель 2012 г 3:20:52 GMT +04:00 Абу-Даби, Маскат
Тема: Motion P1788/M0031:Constructors NO

   I vote NO on this proposal.  In order for me to vote YES, the motion
would need be changed to provide clearly defined behavior in several cases:

   * When the conditions for nums2bareinterval(l,u) are not correctly
specified.

   * When the string passed to test2bareinterval(t) is not accepted.

   The standards must give defined behaviors in these cases.

   I am also reticent to approve use of NaI unless better mechanisms are
impossible to use (e.g. constructors that throw exceptions, which will
never cause "invalid" intervals to be constructed, which eliminates the
need to check for NaI everywhere else in code, which is a potentially
large savings in code complexity and performance.)

-- 
  Alan Eliasen
  eliasen@xxxxxxxxxxxxxx
  http://futureboy.us/