Dealing with InterruptedException, the right way.
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Fri, 2 Dec 2016 22:20:14 +0000 (23:20 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 4 Dec 2016 22:28:56 +0000 (23:28 +0100)
Allgemeines/RxJava/src/main/java/de/rxjava/tests/service/impl/AsyncHTTPClient.java

index 5dd7ca2..331356d 100644 (file)
@@ -1,6 +1,7 @@
 package de.rxjava.tests.service.impl;
 
 import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URL;
 
 import de.rxjava.tests.httpclient.CustomHTTPClient;
@@ -32,6 +33,8 @@ public class AsyncHTTPClient {
        try {   
                        Thread.sleep(30000);
                } catch (InterruptedException exception) {
+                       // Do not forget good patterns when dealing with InterruptedException :(
+                       Thread.currentThread().interrupt();
                }
 
        }
@@ -51,7 +54,12 @@ public class AsyncHTTPClient {
                                
                                // Making it slower as if having a bad connection :)
                                Thread.sleep(2000);
-                       } catch (IOException | InterruptedException exception) {
+                       } catch (InterruptedException exception) {
+                               // Do not forget good patterns when dealing with InterruptedException :(
+                               Thread.currentThread().interrupt();
+                               
+                               observer.onError(exception);
+                       } catch (IOException exception) {
                                observer.onError(exception);
                        }