Strange dependence of object display behavior on debugger state
Consider the following simple classdef,
classdef myclass
properties (Dependent)
data
end
methods
function val=get.data(obj)
error(‘ ‘)
end
function keyboard(obj)
keyboard
end
end
end
When I create an object, and try to display it at the command line, I get a different response, depending on the debugger state, as illustrated below.
>>obj=myclass;
>> dbclear all; obj
obj =
myclass with no properties.
>> dbclear all; dbstop if error; obj
obj =
myclass with no properties.
>> dbclear all; dbstop if caught error; obj
obj =
Caught-error breakpoint was hit in myclass>myclass.get.data at line 10. The error was:
Error using myclass/get.data
10 error(‘ ‘)
K>>
So it would seem that the default display() method uses try/catch to intercept errors in get.property() methods.
As a side note, I feel it is dangerously misleading for the default display() to hide the error completely and to tell the user that myclass has "no properties" when clearly that is not true. But let’s leave that aside for now.
The thing I find really odd is that in the Matlab Editor, when one hovers the mouse over the object to see its properties, the above behavior appears to be reversed. In particular, if we do,
dbclear all; dbstop if caught error; obj.keyboard
and hover the mouse as shown in the screenshot below, we are now told that obj has no properties:
Suddenly, however, dbstop if error is sufficient to intercept the error in get.data().
dbclear all; dbstop if error; obj.keyboard
To reproduce the result in the screenshot below, you must once again hover over obj in Line 14. The debugger will then break at Line 10, as shown below, but only for a short time (about 5 sec).
So, the question. How do we make sense of this behavior, and is it intended?Consider the following simple classdef,
classdef myclass
properties (Dependent)
data
end
methods
function val=get.data(obj)
error(‘ ‘)
end
function keyboard(obj)
keyboard
end
end
end
When I create an object, and try to display it at the command line, I get a different response, depending on the debugger state, as illustrated below.
>>obj=myclass;
>> dbclear all; obj
obj =
myclass with no properties.
>> dbclear all; dbstop if error; obj
obj =
myclass with no properties.
>> dbclear all; dbstop if caught error; obj
obj =
Caught-error breakpoint was hit in myclass>myclass.get.data at line 10. The error was:
Error using myclass/get.data
10 error(‘ ‘)
K>>
So it would seem that the default display() method uses try/catch to intercept errors in get.property() methods.
As a side note, I feel it is dangerously misleading for the default display() to hide the error completely and to tell the user that myclass has "no properties" when clearly that is not true. But let’s leave that aside for now.
The thing I find really odd is that in the Matlab Editor, when one hovers the mouse over the object to see its properties, the above behavior appears to be reversed. In particular, if we do,
dbclear all; dbstop if caught error; obj.keyboard
and hover the mouse as shown in the screenshot below, we are now told that obj has no properties:
Suddenly, however, dbstop if error is sufficient to intercept the error in get.data().
dbclear all; dbstop if error; obj.keyboard
To reproduce the result in the screenshot below, you must once again hover over obj in Line 14. The debugger will then break at Line 10, as shown below, but only for a short time (about 5 sec).
So, the question. How do we make sense of this behavior, and is it intended? Consider the following simple classdef,
classdef myclass
properties (Dependent)
data
end
methods
function val=get.data(obj)
error(‘ ‘)
end
function keyboard(obj)
keyboard
end
end
end
When I create an object, and try to display it at the command line, I get a different response, depending on the debugger state, as illustrated below.
>>obj=myclass;
>> dbclear all; obj
obj =
myclass with no properties.
>> dbclear all; dbstop if error; obj
obj =
myclass with no properties.
>> dbclear all; dbstop if caught error; obj
obj =
Caught-error breakpoint was hit in myclass>myclass.get.data at line 10. The error was:
Error using myclass/get.data
10 error(‘ ‘)
K>>
So it would seem that the default display() method uses try/catch to intercept errors in get.property() methods.
As a side note, I feel it is dangerously misleading for the default display() to hide the error completely and to tell the user that myclass has "no properties" when clearly that is not true. But let’s leave that aside for now.
The thing I find really odd is that in the Matlab Editor, when one hovers the mouse over the object to see its properties, the above behavior appears to be reversed. In particular, if we do,
dbclear all; dbstop if caught error; obj.keyboard
and hover the mouse as shown in the screenshot below, we are now told that obj has no properties:
Suddenly, however, dbstop if error is sufficient to intercept the error in get.data().
dbclear all; dbstop if error; obj.keyboard
To reproduce the result in the screenshot below, you must once again hover over obj in Line 14. The debugger will then break at Line 10, as shown below, but only for a short time (about 5 sec).
So, the question. How do we make sense of this behavior, and is it intended? oop, debug, display, disp, matlab editor, properties, classdef MATLAB Answers — New Questions