フィルターのクリア

How to reiterate the function automatically if my code stops working because my internet disconnected

1 回表示 (過去 30 日間)
Hello,
I want to get weather data from a URL given below:
xdom = xmlread('http://api.openweathermap.org/data/2.5/forecast? q=Texel,NL&mode=xml&APPID=f3e1e8697d3d20e5d91f193ef02e4846')
Now my whole code is running properly, but due to bad internet connection my code stopped. To safeguard my whole code that it doesn't happen again, I want to develop a code which will help in reiterating the code after every 30 seconds until the internet connection is restored. Can someone help me with the same.

採用された回答

Jan
Jan 2015 年 4 月 14 日
How does this code stop? With an error message? Then TRY-CATCH is a direct solution:
success = false;
while ~success
try
xdom = xmlread('...');
success = true;
catch ME
disp('Failed:');
disp(ME.message);
pause(30);
end
end
  1 件のコメント
Punit Gandhi
Punit Gandhi 2015 年 4 月 15 日
Hey Jan,
Thanks for the code. It works perfectly. It shows me this error when internet connection is not working.
>> isnet Failed: Java exception occurred: java.net.UnknownHostException: api.openweathermap.org
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall Web Services from MATLAB Using HTTP についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by