help-octave
[Top][All Lists]
Advanced

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

Re: Message Id for undefined function


From: Juan Pablo Carbajal
Subject: Re: Message Id for undefined function
Date: Tue, 3 Jul 2012 16:52:12 +0200

On Tue, Jul 3, 2012 at 4:43 PM, Ben Abbott <address@hidden> wrote:
>
> On Jun 22, 2012, at 11:26 AM, Juan Pablo Carbajal wrote:
>
>> Hi all,
>>
>> I just realized that there is no message ID when a function is not
>> found in the current path. Example
>>
>> octave:184> my_function_loca  % This function doesn't exist
>> error: `my_function_loca' undefined near line 184 column 1
>> octave:184> [msg id] = lasterr
>> msg = `my_function_loca' undefined near line 184 column 1
>> id =
>>
>> I am trying to write a try-catch block that catches that error. What can I 
>> do?
>>
>> Thanks
>>
>> --
>> M. Sc. Juan Pablo Carbajal
>
> Juan,
>
> I'm not sure what you're looking to do.  When I save the function below in 
> foobar.m and then type "foobar ()" ...
>
> function ret = foobar ()
>   try
>     fubar ();
>   catch
>     ret = lasterror;
>   end
> endfunction
>
> ... I get ...
>
> ans =
>
>   scalar structure containing the fields:
>
>     message = `fubar' undefined near line 24 column 5
>     identifier =
>     stack =
>
>       scalar structure containing the fields:
>
>         file = /Users/bpabbott/Development/mercurial/octave/foobar.m
>         name = foobar
>         line =  24
>         column =  5
>         scope =  2
>         context = 0
>
> In Matlab, I see ...
>
>>> foobar ()
>
> ans =
>
>        message: 'Undefined function or variable 'fubar'.'
>     identifier: 'MATLAB:UndefinedFunction'
>          stack: [1x1 struct]
>
> I you are looking to have the identifier set (something like 
> "Octave:undefindedfunction" ?), then a quick parse of the src directory 
> indicates pt-id.cc is where this error is found.
>
>         $ fgrep -n 'undefined near line' *.cc
>         pt-id.cc:54:    ::error ("`%s' undefined near line %d column %d",
>
> The function is ...
>
> void
> tree_identifier::eval_undefined_error (void)
> {
>   int l = line ();
>   int c = column ();
>
>   maybe_missing_function_hook (name ());
>   if (error_state)
>     return;
>
>   if (l == -1 && c == -1)
>     ::error ("`%s' undefined", name ().c_str ());
>   else
>     ::error ("`%s' undefined near line %d column %d",
>              name ().c_str (), l, c);
> }
>
> I'm not familiar with this part of the code, and have no idea where the ID 
> might be set.  Anyone?
>
> Ben
>

Thank you Max and Ben,

Using the msg for error catching sounds dirty to me. I will try to
search for other errors that do output and id and see if I can send a
patch for the function Ben discovered. I may be slow here, lots of
paperwork!


-- 
M. Sc. Juan Pablo Carbajal
-----
PhD Student
University of Zürich
http://ailab.ifi.uzh.ch/carbajal/


reply via email to

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