@@ -75,33 +75,35 @@ private void makeRequestWithRetries() throws IOException {
75
75
boolean retry = true ;
76
76
IOException cause = null ;
77
77
HttpRequestRetryHandler retryHandler = client .getHttpRequestRetryHandler ();
78
- while (retry ) {
79
- try {
80
- makeRequest ();
81
- return ;
82
- } catch (UnknownHostException e ) {
83
- // switching between WI-FI and mobile data networks can cause a retry which then results in an UnknownHostException
84
- // while the WI-FI is initialising. The retry logic will be invoked here, if this is NOT the first retry
85
- // (to assist in genuine cases of unknown host) which seems better than outright failure
86
- cause = new IOException ("UnknownHostException exception: " + e .getMessage ());
87
- retry = (executionCount > 0 ) && retryHandler .retryRequest (cause , ++executionCount , context );
88
- } catch (IOException e ) {
89
- cause = e ;
90
- retry = retryHandler .retryRequest (cause , ++executionCount , context );
91
- } catch (NullPointerException e ) {
92
- // there's a bug in HttpClient 4.0.x that on some occasions causes
93
- // DefaultRequestExecutor to throw an NPE, see
94
- // http://code.google.com/p/android/issues/detail?id=5255
95
- cause = new IOException ("NPE in HttpClient: " + e .getMessage ());
96
- retry = retryHandler .retryRequest (cause , ++executionCount , context );
97
- } catch (Exception e ) {
98
- // catch anything else to ensure failure message is propagated
99
- cause = new IOException ("Unhandled exception: " + e .getMessage ());
100
- retry = false ;
101
- }
102
- if (retry && (responseHandler != null )) {
103
- responseHandler .sendRetryMessage ();
78
+ try
79
+ {
80
+ while (retry ) {
81
+ try {
82
+ makeRequest ();
83
+ return ;
84
+ } catch (UnknownHostException e ) {
85
+ // switching between WI-FI and mobile data networks can cause a retry which then results in an UnknownHostException
86
+ // while the WI-FI is initialising. The retry logic will be invoked here, if this is NOT the first retry
87
+ // (to assist in genuine cases of unknown host) which seems better than outright failure
88
+ cause = new IOException ("UnknownHostException exception: " + e .getMessage ());
89
+ retry = (executionCount > 0 ) && retryHandler .retryRequest (cause , ++executionCount , context );
90
+ } catch (IOException e ) {
91
+ cause = e ;
92
+ retry = retryHandler .retryRequest (cause , ++executionCount , context );
93
+ } catch (NullPointerException e ) {
94
+ // there's a bug in HttpClient 4.0.x that on some occasions causes
95
+ // DefaultRequestExecutor to throw an NPE, see
96
+ // http://code.google.com/p/android/issues/detail?id=5255
97
+ cause = new IOException ("NPE in HttpClient: " + e .getMessage ());
98
+ retry = retryHandler .retryRequest (cause , ++executionCount , context );
99
+ }
100
+ if (retry && (responseHandler != null )) {
101
+ responseHandler .sendRetryMessage ();
102
+ }
104
103
}
104
+ } catch (Exception e ) {
105
+ // catch anything else to ensure failure message is propagated
106
+ cause = new IOException ("Unhandled exception: " + e .getMessage ());
105
107
}
106
108
107
109
// cleaned up to throw IOException
0 commit comments