aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorichbinjoe <joe@ibj.io>2015-10-02 12:30:06 -0400
committerichbinjoe <joe@ibj.io>2015-10-02 12:30:06 -0400
commitcadb9c6abc314deb924f86534aa2284dd2dbf6a3 (patch)
treeebf6fb50e8cfbc4208afc5ed96b13ac6f62e0dde
parent78caaec86ca3d44146fde340ad05bcbfe7ca6d23 (diff)
Add OvenException for oven related internal exceptions
-rw-r--r--src/main/java/org/drtshock/OvenException.java12
-rw-r--r--src/main/java/org/drtshock/Potato.java12
2 files changed, 20 insertions, 4 deletions
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;
+ }
}
/**