bugGNU Octave - Bugs: bug #48175, "parse error" error...


bug #48175: "parse error" error message in GUI callbacks

Submitter:  Guillaume <gyom>
Submitted:  Wed 08 Jun 2016 12:05:40 PM UTC
Category:  Octave Function Severity:  1 - Wish
Priority:  4 Item Group:  Feature Request
Status:  Fixed Assigned to:  None
Originator Name:  Guillaume Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup

Jump to the original submission

Sat 11 Jun 2016 01:41:02 AM UTC, comment #8: 

Oops, I totally misread comment #2 and was thinking the error was the same before and after the callback executed. You had it right to begin with,


Mike Miller <mtmiller>
Group Member
Sat 11 Jun 2016 01:27:25 AM UTC, comment #7: 

I'm not sure we care to be 100% compatible, but Matlab stores the message "Error while evaluating UIControl Callback" in the lasterror field.  Wouldn't it be simpler not to save/restore the lasterror state?  Or just leave it alone so it had the error message from inside the callback itself?

Rik <rik5>
Group administrator
Sat 11 Jun 2016 12:40:24 AM UTC, comment #6: 

Thanks for the idea. I changed this yet a little more by saving and restoring the last error structure to what it was before the callback was called,


Mike Miller <mtmiller>
Group Member
Fri 10 Jun 2016 04:57:01 AM UTC, comment #5: 

@Mike: Take a look at my newly uploaded diff.  I fake the error message by writing to std::cerr and then set the internal error message by calling the Octave function lasterr().

-          eval_string (s, false, status, 0);
+          try
+            {
+              eval_string (s, false, status, 0);
+            }
+          catch (octave_execution_exception&)
+            {
+              std::cerr << "execution error in graphics callback function" <<
+                           std::endl;
+              feval ("lasterr",
+                     ovl ("execution error in graphics callback function"));
+              recover_from_exception ();
+            }

Feel free to modify the message, or to commit the change.

(file #37442)

Rik <rik5>
Group administrator
Thu 09 Jun 2016 06:11:41 PM UTC, comment #4: 

Well the attached diff works for me, with both string and function handle callbacks in place. This definitely gets rid of the "parse error" message and only shows the intended callback message. But it still sets lasterror to the message originating in the callback. Some more tweaking will be necessary if it's also important that the global error state is not changed when the callback executes.

(file #37440)

Mike Miller <mtmiller>
Group Member
Thu 09 Jun 2016 05:30:19 PM UTC, comment #3: 

Changing this report to a Feature Request and lowering the Severity and Priority.  Octave behaves equivalently to Matlab, except the error message is less informative.

I don't know if it can be fixed, but the place to fix it will be in libinterp/corefcn/graphics.cc.  The function in question is gh_manager::do_execute_callback().  If the callback is a string, then eval_string is called, if it is anything else then feval is called.

Interestingly, there are differences between eval_string and feval.  The example in comment #0 used a string for the callback.  The following code uses a function handle.

close all;
h = figure;
fcn = @() error ("My Error Msg");
uicontrol(h,'style','pushbutton','callback', fcn);

Just for grins, I put the feval in do_execute_callback inside a try/catch block. 

if (fcn)
        feval (fcn, args);
    catch (...)
        error ("Error executing callback\n");

And running now produces

error: My Error Msg
error: Error executing callback
error: parse error

It works to produce the new error message, but I also get a "parse error" message.  This must be coming from the parser itself in parse-tree/oct-parse.cc

Rik <rik5>
Group administrator
Thu 09 Jun 2016 10:57:16 AM UTC, comment #2: 

Here is what happens with Matlab:

>> lasterror reset
>> uicontrol(figure,'style','pushbutton','callback','error(''error msg'');');
>> lasterror

ans =

  struct with fields:

       message: ''
    identifier: ''
         stack: [0×1 struct]

>> % click button
>> error msg

Error while evaluating UIControl Callback

>> lasterror

ans =

  struct with fields:

       message: 'Error while evaluating UIControl Callback'
    identifier: ''
         stack: [0×1 struct]

Guillaume <gyom>
Wed 08 Jun 2016 06:43:10 PM UTC, comment #1: 

Confirmed here.

What does Matlab's lasterror function show after calling uicontrol but before actually clicking on the button? What does lasterror show after clicking on the button?

Mike Miller <mtmiller>
Group Member
Wed 08 Jun 2016 12:05:40 PM UTC, original submission:  

When an error is thrown during the execution of a uicontrol callback (that does not contain any syntax error), a "parse error" error message is displayed:

>> h = figure;
>> uicontrol(h,'style','pushbutton','callback','error(''error msg'');');
>> error: error msg
error: parse error

It seems slightly misleading. In the same context, Matlab displays "Error while evaluating UIControl Callback".

Guillaume <gyom>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #37442:  bug_48175-2.diff added by rik5 (2KiB - application/x-download)
file #37440:  bug-48175.diff added by mtmiller (1010B - text/x-diff)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by gyom (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.


    Follow 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-06-11 mtmiller StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2016-06-10 rik5 Attached File- Added bug_48175-2.diff, #37442
    2016-06-09 mtmiller Attached File- Added bug-48175.diff, #37440
        CategoryGUI Octave Function
        StatusNeed Info Patch Submitted
    2016-06-09 rik5 Severity3 - Normal 1 - Wish
        Priority5 - Normal 4
        Item GroupNone Feature Request
    2016-06-08 mtmiller StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code