octave-maintainers
[Top][All Lists]
Advanced

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

Behavior of feval when it fails?


From: Rik
Subject: Behavior of feval when it fails?
Date: Wed, 2 Nov 2016 14:40:00 -0700

All,

I was looking into a bug report and found that the feval function fails
silently.  See test code below.

+verbatim+
octave:1> feval ('sin', 1)                                       
ans =  0.84147                                                   
octave:2> feval ('sinABC', 1)                                       
octave:3>                                                              
-verbatim-

It seems like feval should most likely throw an error if the function
doesn't exist.  But maybe we get in to weird loops where feval is called
repeatedly.  The code for feval is in oct-parse.cc.

+verbatim+
octave_value_list
feval (const std::string& name, const octave_value_list& args, int nargout)
{
  octave_value_list retval;

  octave_value fcn = symbol_table::find_function (name, args);

  if (fcn.is_defined ())
    retval = fcn.do_multi_index_op (nargout, args);
  else
    {
      try
        {
          maybe_missing_function_hook (name);
        }
      catch (octave::execution_exception& e)
        {
          error (e, "feval: function '%s' not found", name.c_str ());
        }
    }

  return retval;
}
-verbatim-

and the maybe_missing_function_hook function calls feval.

+verbatim+
void maybe_missing_function_hook (const std::string& name)
{
  // Don't do this if we're handling errors.
  if (buffer_error_messages == 0 && ! Vmissing_function_hook.empty ())
    {
      octave_value val = symbol_table::find_function (Vmissing_function_hook);

      if (val.is_defined ())
        {
          // Ensure auto-restoration.
          octave::unwind_protect frame;
          frame.protect_var (Vmissing_function_hook);

          // Clear the variable prior to calling the function.
          const std::string func_name = Vmissing_function_hook;
          Vmissing_function_hook.clear ();

          // Call.
          feval (func_name, octave_value (name));
        }
    }
}
-verbatim-

Maybe the Vmissing_function_hook function should return a value that
indicates whether the hook handled the exception or not.  If it didn't then
it could report that back to the caller?  Anyone have a good idea on this?

--Rik





reply via email to

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