MATLAB Answers


Timer function exception won't propagate to the calling script

Asked by Zhong
on 24 Jun 2013

I created a script matlab 2009b in which I have the try-catch block. And in the timerfunction myTimerFunc, there is a java network URL connection class. When there is a network outage, exception is "rethrow" from myTimerFunc. I expect this exception to propagate to the calling script, where the network exception is handled. However, in reality, the timer dies and timer stop function is invoked. Can anyone tell why this exception cannot be propagate to the calling chain or matlab timer is designed that way?


    tasksToExecute = (buffLen)/period - pVCtr;
    t = timer('StartDelay', 0, 'Period', period , 'TasksToExecute', tasksToExecute , 'ExecutionMode', 'fixedRate');
    t.StartFcn = {@my_callback_fcn, 'list starts'};
    t.StopFcn = { @my_callback_fcn2, 'Logout',httpsUrl, logoutJ};
    t.TimerFcn = @(x,y)myTimerFunc(httpsUrl, dir, buffLen);
 catch err
    % If there is network error, log out and restart it.     
    if pVCtr*period < buffLen
           subScript;  %restart subScript using new log in.    
       disp 'subScript is done'

%------------exception----------- 4. throw err4 ==>get socket inputstream error ??? Error while evaluating TimerFcn for timer 'timer-1'

Java exception occurred: Read timed out

at Method)

at Source)

at Source)

at Source)

at Source)

at Source)

at Source)

at Source)

at Source)

at Source)

at Source)

at Source)

at Source)

at Source)

at com.mathworks.jmi.NativeMatlab.SendMatlabMessage(Native Method)

at com.mathworks.jmi.NativeMatlab.sendMatlabMessage(

at com.mathworks.jmi.MatlabLooper.sendMatlabMessage(

at com.mathworks.jmi.Matlab.mtFevalConsoleOutput(

at com.mathworks.jmi.MatlabMCR.mtFevalConsoleOutput(

at com.mathworks.timer.MWCallback$

at com.mathworks.jmi.NativeMatlab.dispatchMTRequests(

StopFcn event occurred at 24-Jun-2013 00:14:17 Logout



No products are associated with this question.

2 Answers

Answer by Zhong
on 24 Jun 2013

Thanks, Isakson. I read your posting (actually before I posted my question). Forgive my tardiness in understanding your posting. I did not see how your "Debug code invoked by timer" related to mine b/c your posting is already a solution to some problem, whereas I can't get the context of the problem. Could you give a few sentences as to where the fix of my problem is. Greatly appreciated your postings.

  1 Comment

My "answer" is triggered by your subject title, "Timer function exception won't propagate to the calling script".

I try to say that "However, in reality, the timer dies and timer stop function is invoked." is expected behavior of Matlab.

The best work-around I've come up with is to put the try,catch,end in the the TimerFcn callback function.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!