From: Gustavo Martin Morcuende Date: Fri, 2 Dec 2016 22:20:14 +0000 (+0100) Subject: Dealing with InterruptedException, the right way. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=4533bed25d88d5f33fa965250d3cc88a9339a6f1;p=JavaForFun Dealing with InterruptedException, the right way. --- 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); }