Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Calling objects error function
Replies: 1   Last Post: Aug 12, 2010 10:48 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Markus Due Jakobsen

Posts: 43
Registered: 4/29/08
Calling objects error function
Posted: Aug 12, 2010 8:47 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.