octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #33217] Matlab's try, ...; catch EXCEPTION, ..


From: anonymous
Subject: [Octave-bug-tracker] [bug #33217] Matlab's try, ...; catch EXCEPTION, ...; end doesn't work (no support for caught error)
Date: Tue, 03 May 2011 13:58:06 +0000
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1

URL:
  <http://savannah.gnu.org/bugs/?33217>

                 Summary: Matlab's try, ...; catch EXCEPTION, ...; end doesn't
work (no support for caught error)
                 Project: GNU Octave
            Submitted by: None
            Submitted on: Tue 03 May 2011 01:58:05 PM UTC
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Feature Request
                  Status: None
             Assigned to: None
         Originator Name: Jochen Weber
        Originator Email: address@hidden
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 3.4.0
        Operating System: Mac OS

    _______________________________________________________

Details:

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).





    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?33217>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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