From 4533bed25d88d5f33fa965250d3cc88a9339a6f1 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Fri, 2 Dec 2016 23:20:14 +0100 Subject: [PATCH] Dealing with InterruptedException, the right way. --- .../java/de/rxjava/tests/service/impl/AsyncHTTPClient.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Allgemeines/RxJava/src/main/java/de/rxjava/tests/service/impl/AsyncHTTPClient.java b/Allgemeines/RxJava/src/main/java/de/rxjava/tests/service/impl/AsyncHTTPClient.java index 5dd7ca2..331356d 100644 --- a/Allgemeines/RxJava/src/main/java/de/rxjava/tests/service/impl/AsyncHTTPClient.java +++ b/Allgemeines/RxJava/src/main/java/de/rxjava/tests/service/impl/AsyncHTTPClient.java @@ -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); } -- 2.1.4