From: Markus Due Jakobsen on
Hi
I have recently started with the matlab OOP.
My question is whether it is possible to capture/catch every error that occurs somewhere (arbitrary) in the object methods, without using try/catch or some sort of error detector like: if x>y then call the error function? In other words, when an error occurs the error should call the objects error function (Errorfcn).

I have created a simple object below. If Prop1/Prop2 is given a value an error occurs when trying to specify M/N. I would like to let this error call the Errorfcn and display the error report (and do some other stuff).

%%%%
classdef SimpleErrorClass < handle
properties
Prop1 = 0;
Prop2 = 1;
end
% events
% Error
% end
methods
function obj = SimpleEventClass(varargin) % Constructor
if nargin>0; obj.Prop1 = varargin{1}; end
end

function set.Prop1(obj,value)
obj.Prop1 = value;
M=rand(3)*rand(4); % This error should call the objects errorfunction
end

function set.Prop2(obj,value)
obj.Prop2 = value;
N=rand(nan); % This error should call the objects errorfunction
end

function Errorfcn(obj,src,evnt)
% This function should display the error report
disp('### Error ####')
err = MException.getReport
end
end
end
%%%

Regards
Markus
From: Steven_Lord on


"Markus Due Jakobsen" <markusdue(a)gmail.com> wrote in message
news:i40qga$11p$1(a)fred.mathworks.com...
> Hi
> I have recently started with the matlab OOP. My question is whether it is
> possible to capture/catch every error that occurs somewhere (arbitrary) in
> the object methods,

Sure. Just wrap the body of each method in TRY/CATCH blocks.

> without using try/catch or some sort of error detector like: if x>y then
> call the error function?

Not as far as I'm aware.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com