I need to download some URLs, and it may happen that some kind of exception may occur during operations, for example java.net.NoRouteToHostException. I consider this a temporary exception, as the download may be successful if you try again after a while.Therefore, I would like to catch all those exceptions related to timing errors, and I started with them: java.net.NoRouteToHostException, java.net.SocketExceptionCan you list any other exceptions, such as these?
java.net.NoRouteToHostException
java.net.SocketException
java.net.SocketExceptionis a parent java.net.NoRouteToHostException, so you can only catch a parent. The remaining children are SocketExceptionequal BindException, ConnectExceptionand PortUnreachableException. Maybe it’s okay to catch only SocketExceptionin your case ...
SocketException
BindException
ConnectException
PortUnreachableException
One pattern that is sometimes useful for solving temporary errors in repeated actions is to define the error callback interface and some classes that implement it; when an error occurs, let the callback know and let it decide whether to throw an exception or whether the action should be repeated. Since existing communication classes do not match this pattern, it may be necessary to catch their exceptions and turn them into callbacks.
, , . , , , .., , - "".
@reef java.net.NoRouteToHostException exntends java.net.SocketException, java.net.SocketException, . java.net.SocketException IOException, , , . IO .
HttpRetryException - . , java.net, SocketException?
( )
try { .... } catch(Exception e) { if(e.getClass().getPackage().getName().equalsIgnoreCase("java.net")) { retry(); } }
Source: https://habr.com/ru/post/1794481/More articles:Availability: state TYPE_NOTIFICATION_STATE_CHANGED - androidHow do I add a view to a Sitemap generated by a Drupal Sitemap XML module? - xmlSQLite query that calculates if the time of the Unix era is today - sqlInclude JAR file in ant compilation - javatype required for function calls using a short data type variable as a parameter - javaC # / Winforms App freeze / lag - multithreadingCakephp Helpers in Views and $ this - standardsЗапрос для перемещения дерева mysql - mysqlhibernate - reduce the number of queries - javaЗапрос представления базы данных дерева (MySQL) - mysqlAll Articles