The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

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
Prop1 = 0;
Prop2 = 1;
% events
% Error
% end
function obj = SimpleEventClass(varargin) % Constructor
if nargin>0; obj.Prop1 = varargin{1}; end

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

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

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


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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.