bugGNU Octave - Bugs: bug #33217, Matlab's try, ...; catch...

 
 

bug #33217: Matlab's try, ...; catch EXCEPTION, ...; end doesn't work (no support for caught error)

Submitter:  None
Submitted:  Tue 03 May 2011 01:58:05 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Jochen Weber Originator Email:  -email is unavailable-
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

Mon 06 Jan 2014 08:56:18 AM UTC, comment #10: 

Well, since nobody applied my patch from comment #6, the new description is not completely true.

Stefan Mahr <dac922>
Mon 06 Jan 2014 02:18:23 AM UTC, comment #9: 

Thanks, I've slightly edited your patch and its commit message. I also rebased it to the stable branch:

http://hg.savannah.gnu.org/hgweb/octave/rev/6fd22474783e

You may wish to remove your pre-edited patch from your local repo:


hg strip -r f07d9cfd22a


Jordi GutiƩrrez Hermoso <jordigh>
Group Member
Sun 05 Jan 2014 05:33:49 PM UTC, comment #8: 

updating docs

(file #30193)

Felipe G. Nievinski <fgnievinski>
Tue 20 Aug 2013 05:27:03 PM UTC, comment #7: 
Stefan Mahr <dac922>
Tue 20 Aug 2013 05:24:55 PM UTC, comment #6: 

For the sake of completeness: jwe pushed a changeset to fix the parser conflicts introduced by my patch
http://hg.savannah.gnu.org/hgweb/octave/rev/923ce8b42db2



In order to reduce the need of explanation in the manual, attached patch makes the result of 'catch exception' compatible to the result of the lasterror function.


(file #28883)

Stefan Mahr <dac922>
Wed 14 Aug 2013 05:28:50 PM UTC, comment #5: 

I suppose this is OK as a temporary solution until we have classdef working and can actually define a proper MException object.  I pushed the change with a few minor changes (commit message and a fix for an apparent cut and paste error in the pt-check file and an addition to the NEWS file).

http://hg.savannah.gnu.org/hgweb/octave/rev/923ce8b42db2

Stefan,

Please take a look at the changes I made to the commit message and try to follow that style and format in the future.  Thanks.

We also need to update the manual for this change.  Could you please take a look at doing that?

John W. Eaton <jwe>
Group administrator
Tue 13 Aug 2013 07:00:20 PM UTC, comment #4: 

Stefan,

I tried your patch.  It works for me.

Since I'm unfamiliar with this part of the code, I suggest you have Jordi, Rik, or jwe look it over and push it.

Ben Abbott <bpabbott>
Group Member
Tue 13 Aug 2013 05:43:50 PM UTC, comment #3: 

Should work now without breaking

try, catch a=1; end



(file #28835)

Stefan Mahr <dac922>
Tue 09 Apr 2013 08:27:12 PM UTC, comment #2: 

I have attached a patch that hopefully helps to solve this issue. It needs further improvements, e.g. support for err.stack (not exported from error.h yet, so err.message and err.identifier only at the moment).

Stefan Mahr <dac922>
Tue 03 Jan 2012 08:40:33 AM UTC, comment #1: 

I think this is an important compatibility issue.

my_caught_error() is a nice idea but it is rather risky. If there are more than one try-catch block in a workspace, it will not work properly unless the user is careful enough to clear my_caught_error. For example:

try,
    TRYBLOCK_1;
catch my_caught_error;
    CATCHBLOCK; % using my_caught_error instead of lasterror
end

try,
    TRYBLOCK_2;
catch my_caught_error;
    % my_caught_error is not valid, it is still the error structure generated at TRYBLOCK_1.
end


Gokberk <gdevel>
Tue 03 May 2011 01:58:05 PM UTC, original submission:  

Syntax like the following doesn't work in Octave (which is OK in Matlab R2007b and onwards without warning/error):


try
    test = non_existing_function(1);
catch errobj
    disp(errobj.message);
end


It seems that Matlab changed the way its error handling syntax works from


try,
    TRYBLOCK;
catch,
    CATCHBLOCK; % using lasterr and lasterror
end


to


try,
    TRYBLOCK;
catch EXCEPTION,
    CATCHBLOCK; % using EXCEPTION, which is of type MException
end


So, as an aside, the return value of lasterror maybe should be of type MException (at least for full compatibility between current releases of Matlab and Octave)?

As a temporary solution I'm using, I've added a function to the path:


function my_caught_error
assignin('caller', 'my_caught_error', lasterror);


which can then be used as follows:


try,
    TRYBLOCK;
catch my_caught_error;
    CATCHBLOCK; % using my_caught_error instead of lasterror
end


Given that Matlab overrides function names in the lookup table with local variables, the function is never called (the interpreter assigns the MException object to the my_caught_error variable/name). In Octave the function is called and then, in the calling workspace (containing the try/catch/end construction), assigns the value of lasterror to my_caught_error. Given that this is a function call, it is important to use a semicolon after the function call/variable name, for otherwise the result will be displayed! Luckily, Matlab does not mind (given that it also, even if grudgingly, supports empty statements).

Anonymous

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #30193:  doc_catcherr.diff added by fgnievinski (3KiB - application/octet-stream)
file #28883:  catchexception.diff added by dac922 (2KiB - text/x-patch)
file #28835:  trycatch4.diff added by dac922 (9KiB - text/x-patch)
file #27832:  trycatch3.diff added by dac922 (8KiB - text/x-patch)
file #27829:  trycatch2.diff added by dac922 (8KiB - text/x-patch - commit message according commit message guidelines)
file #27828:  trycatch1.diff added by dac922 (7KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jordigh (Posted a comment)
  • -email is unavailable- added by fgnievinski (Updated the item)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by dac922 (Updated the item)
  • -email is unavailable- added by gdevel (Posted a comment)
  • -email is unavailable- added by bpabbott (Updated the item)
  • -email is unavailable- added by None (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 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-01-05 fgnievinski Attached File- Added doc_catcherr.diff, #30193
    2013-08-20 dac922 Attached File- Added catchexception.diff, #28883
    2013-08-14 jwe StatusNone Fixed
        Open/ClosedOpen Closed
    2013-08-13 dac922 Attached File- Added trycatch4.diff, #28835
    2013-04-10 dac922 Attached File- Added trycatch3.diff, #27832
    2013-04-09 dac922 Attached File- Added trycatch2.diff, #27829
    2013-04-09 bpabbott Release3.4.0 dev
        Operating SystemMac OS Any
    2013-04-09 dac922 Attached File- Added trycatch1.diff, #27828
    2011-09-18 bpabbott Item GroupFeature Request Matlab Compatibility

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code