bugGNU Octave - Bugs: bug #63806, catch block output is displayed...

 
 

bug #63806: catch block output is displayed after text from rethrow (Matlab Compatibility)

Submitter:  Rik <rik5>
Submitted:  Tue 14 Feb 2023 03:45:06 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 14 Feb 2023 04:31:06 PM UTC, comment #2: 

Interestingly, we are already trying to do the right thing here.  Try this code which adds a call to warning().


try
  z = zeros (2^53,1);
catch ME
  disp ('in catch block');
  warning ("warning in catch block");
  rethrow (ME);
end


which results in


in catch block
warning: warning in catch block
warning: called from
    blah at line 5 column 3

error: out of memory or dimension too large for Octave's index type
error: called from
    blah at line 2 column 5


So, apparently the warning function does flush stdout before proceeding.  Given that Octave is an exception state, performance isn't important.  It seems like rethrow() should borrow the code that warning() uses and flush stdout before proceeding.

Rik <rik5>
Group administrator
Tue 14 Feb 2023 03:52:21 PM UTC, comment #1: 

See also bug #40828, comment #22, where I noted that there are some issues with the info stored in MException objects.  That's something I'd like to fix for Octave 9 and I will try to look at this problem at the same time.

John W. Eaton <jwe>
Group administrator
Tue 14 Feb 2023 03:45:06 PM UTC, original submission:  

Sample code:


try
  z = zeros (2^53,1);
catch ME
  disp ('in catch block');
  rethrow (ME);
end


When run in Octave it produces the output:


error: out of memory or dimension too large for Octave's index type
error: called from
    tst_rethrow_ordering at line 2 column 5
in catch block


In Matlab, the code in the catch block that precedes the rethrow () call is executed first and printed first.  This seems more logical as execution is from top to bottom.

One can resolve this by adding "fflush (stdout)" before the call to rethrow(), but it would probably be better to have rethrow do the flushing.

Rik <rik5>
Group administrator

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #54356:  tst_rethrow_ordering.m added by rik5 (82B - text/x-matlab)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5 (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.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-02-14 rik5 Attached File- Added tst_rethrow_ordering.m, #54356

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code