Add OvenException for oven related internal exceptions

This commit is contained in:
ichbinjoe 2015-10-02 12:30:06 -04:00
parent 78caaec86c
commit cadb9c6abc
2 changed files with 20 additions and 4 deletions

View file

@ -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);
}
}

View file

@ -72,8 +72,9 @@ public class Potato implements Tuber {
* Checks if the potato is put into the oven. * Checks if the potato is put into the oven.
* *
* @return true if potato is in the oven, false if otherwise * @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 { try {
final URL url = new URL("https://www.google.com/search?q=potato"); final URL url = new URL("https://www.google.com/search?q=potato");
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@ -82,8 +83,7 @@ public class Potato implements Tuber {
int inOven = connection.getResponseCode(); int inOven = connection.getResponseCode();
return inOven == 200; return inOven == 200;
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); throw new OvenException(ex);
return false;
} }
} }
@ -93,7 +93,11 @@ public class Potato implements Tuber {
* @return true if this potato is baked, false if otherwise * @return true if this potato is baked, false if otherwise
*/ */
public boolean isBaked() { public boolean isBaked() {
return this.isPutIntoOven(); try {
return this.isPutIntoOven();
} catch (OvenException e) {
return false;
}
} }
/** /**