From cadb9c6abc314deb924f86534aa2284dd2dbf6a3 Mon Sep 17 00:00:00 2001 From: ichbinjoe Date: Fri, 2 Oct 2015 12:30:06 -0400 Subject: [PATCH] Add OvenException for oven related internal exceptions --- src/main/java/org/drtshock/OvenException.java | 12 ++++++++++++ src/main/java/org/drtshock/Potato.java | 12 ++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/drtshock/OvenException.java diff --git a/src/main/java/org/drtshock/OvenException.java b/src/main/java/org/drtshock/OvenException.java new file mode 100644 index 0000000..6ed512b --- /dev/null +++ b/src/main/java/org/drtshock/OvenException.java @@ -0,0 +1,12 @@ +package org.drtshock; + +/** + * Created by Joe Hirschfeld on 10/2/2015. + */ +public class OvenException extends Exception { + + public OvenException(Exception internalException){ + super(internalException); + } + +} diff --git a/src/main/java/org/drtshock/Potato.java b/src/main/java/org/drtshock/Potato.java index 670807a..83690c3 100644 --- a/src/main/java/org/drtshock/Potato.java +++ b/src/main/java/org/drtshock/Potato.java @@ -72,8 +72,9 @@ public class Potato implements Tuber { * Checks if the potato is put into the oven. * * @return true if potato is in the oven, false if otherwise + * @throws OvenException if the oven encounters an internal exception */ - public boolean isPutIntoOven() { + public boolean isPutIntoOven() throws OvenException { try { final URL url = new URL("https://www.google.com/search?q=potato"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); @@ -82,8 +83,7 @@ public class Potato implements Tuber { int inOven = connection.getResponseCode(); return inOven == 200; } catch (IOException ex) { - ex.printStackTrace(); - return false; + throw new OvenException(ex); } } @@ -93,7 +93,11 @@ public class Potato implements Tuber { * @return true if this potato is baked, false if otherwise */ public boolean isBaked() { - return this.isPutIntoOven(); + try { + return this.isPutIntoOven(); + } catch (OvenException e) { + return false; + } } /**