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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

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?

%--------------------Script------------------

 try
    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);
    start(t)
 catch err
    % If there is network error, log out and restart it.     
    if pVCtr*period < buffLen
           subScript;  %restart subScript using new log in.    
    else
       disp 'subScript is done'
    end
 end    

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

Java exception occurred: java.net.SocketTimeoutException: Read timed out

at java.net.SocketInputStream.socketRead0(Native Method)

at java.net.SocketInputStream.read(Unknown Source)

at com.sun.net.ssl.internal.ssl.InputRecord.readFully(Unknown Source)

at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(Unknown Source)

at com.sun.net.ssl.internal.ssl.AppInputStream.read(Unknown Source)

at java.io.BufferedInputStream.fill(Unknown Source)

at java.io.BufferedInputStream.read1(Unknown Source)

at java.io.BufferedInputStream.read(Unknown Source)

at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)

at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)

at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)

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

at com.mathworks.jmi.NativeMatlab.sendMatlabMessage(NativeMatlab.java:211)

at com.mathworks.jmi.MatlabLooper.sendMatlabMessage(MatlabLooper.java:121)

at com.mathworks.jmi.Matlab.mtFevalConsoleOutput(Matlab.java:1458)

at com.mathworks.jmi.MatlabMCR.mtFevalConsoleOutput(MatlabMCR.java:1135)

at com.mathworks.timer.MWCallback$callbackEvent.run(MWCallback.java:551)

at com.mathworks.jmi.NativeMatlab.dispatchMTRequests(NativeMatlab.java:335)

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

0 Comments

Zhong

Products

No products are associated with this question.

2 Answers

Answer by per isakson on 24 Jun 2013

0 Comments

per isakson
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

per isakson on 24 Jun 2013

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.

Zhong

Contact us