bugGNU Octave - Bugs: bug #63807, Add function throw() for Matlab...

 
 

bug #63807: Add function throw() for Matlab Compatibility

Submitter:  Rik <rik5>
Submitted:  Tue 14 Feb 2023 04:19:34 PM UTC
   
 
Category:  Octave Function Severity:  1 - Wish
Priority:  5 - Normal Item Group:  Feature Request
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 06 Mar 2023 09:43:38 PM UTC, comment #5: 

Hello sir / madam I like to work on this for GSoC. Are you GSoC mentor? I know C++ very well and we learned all about advanced C++ techniques at Maharaja Sayajirao University including try throw and even catch statement. We also learned how to manage a supply chain warehouse with C++ code. Please tell me where to add this throw statement and I will add it there and also add catch statement. Yours sincerely. Uttam Khobragade.

Anonymous
Wed 15 Feb 2023 01:20:43 AM UTC, comment #4: 

For error(), Matlab documentation is explicit that the input is a scalar struct.  It just happens to look a lot like what you would get if you did "struct (MException)".

Rik <rik5>
Group administrator
Tue 14 Feb 2023 06:11:19 PM UTC, comment #3: 

I intend to restructure things a bit with the fix for bug #40828 so that the MEXception object will pick up the stack information in an internal catch block in the evaluator, where the info is most easily accessible.  At least I think that will work.

Fixing MException to work properly should also give us the "throw" function.  I don't think we need to try to add it separately before fixing MException.

John W. Eaton <jwe>
Group administrator
Tue 14 Feb 2023 05:59:08 PM UTC, comment #2: 

Exceptions are objects (not structures) in Matlab. `throw` is a method of the MException class.
ISTR, that at some point in the past, we didn't want to implement getReport as a function because it also is a method of the MException class in Matlab. Should the same apply here?

Markus Mützel <mmuetzel>
Group administrator
Tue 14 Feb 2023 04:35:59 PM UTC, comment #1: 

In addition, Matlab's error() function now accepts and EXCEPTION structure as input.  One potential solution is to expand Octave's error function to support that syntax and then throw() essentially becomes an alias for calling error() with a structure input (because error() already has to figure out where in the code it was called).

Rik <rik5>
Group administrator
Tue 14 Feb 2023 04:19:34 PM UTC, original submission:  

Octave has the function rethrow(EXCEPTION) which throws an exception using the provided EXCEPTION structure.  When rethrowing an exception, Octave uses the stack field from the structure which points to where the exception originated.  Matlab has an additional function throw(EXCEPTION) which throws an exception, but the stack field contains the location where the throw() command was executed.  An example:


try
  error ("emitting an error");   # line 2
catch EXCEPTION
  rethrow (EXCEPTION);           # line 4
  #throw (EXCEPTION);             # line 5
end


Output in Octave is


error: emitting an error
error: called from
    tst_throw at line 2 column 3


If rethrow() is commented out and throw() existed then the output would be


error: emitting an error
error: called from
    tst_throw at line 5 column 3


This seems like a relatively easy function to add since, for example, the error() function already has the code to figure out where it is being called from in an m-file.

Rik <rik5>
Group administrator

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

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 mmuetzel (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.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code