octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: error function


From: Shai Ayal
Subject: Re: error function
Date: Tue, 15 May 2007 19:14:31 +0300

On 5/15/07, John W. Eaton <address@hidden> wrote:
On 15-May-2007, Shai Ayal wrote:

| On 5/15/07, John W. Eaton <address@hidden> wrote:
| > The string_value method calls error if it can't perform the
| > conversion.
|
| but no error messge is printed right? does it call error ("") ?

Yes, it calls error and prints a message.  The only function that is
supposed to set error_state is error.

| > Maybe you need
| >
| >  bool rgb_property::is_none (void) const;
| >  bool rgb_property::is_auto (void) const;
| >  const double *rgb_property::rgb_value (void) const;
| >
| > and then code that uses this class will just have to check if it cares
| > about "none" and "auto".  I don't know what else to suggest unless the
| > rgb function can somehow return reasonable values when the state is
| > "none" or "auto".
|
| I thought of is_rgb and is_radio. However I recal thatusing is_*
| functions was the way to determine octave_value type, but then I read
| somewhere that the recomended way was to try and convert and than
| check error_state, as above. Can you elaborate on why this is
| recommended for octave_value?

There are different cases where different things are appropriate.  For
example, a function that always expects a double value as its first
argument and for which everything else is an error should use
something like

  double x = arg.double_value ();
  if (! error_state)
    ...

because that is better than checking for all possible types that might
have methods which allow them to be converted to double values.

But if a function can accept a character string or a double value as
its first argument, then you are forced to use something like

  if (arg.is_string ())
    {
      std::string s = arg.string_value ();
    }
  else
    {
      double = arg.double_value ();

      if (! error_state)
        ...
    }

OK, I think I got it now. Thanks for the explanation


Yes, it might be better if Octave used exceptions but Octave's
interpreter was written before C++ had exceptions (or even a standard
library).  Changing it now would be a lot of work.

no complaints here. I just wasn't sure.

Shai


reply via email to

[Prev in Thread] Current Thread [Next in Thread]