Timer function exception won't propagate to the calling script
Afficher commentaires plus anciens
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
Réponses (2)
per isakson
le 24 Juin 2013
0 votes
Zhong
le 24 Juin 2013
0 votes
1 commentaire
per isakson
le 24 Juin 2013
Modifié(e) : per isakson
le 25 Juin 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.
Catégories
En savoir plus sur Get Started with Microsoft .NET dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!