Add OvenException for oven related internal exceptions
This commit is contained in:
parent
78caaec86c
commit
cadb9c6abc
2 changed files with 20 additions and 4 deletions
12
src/main/java/org/drtshock/OvenException.java
Normal file
12
src/main/java/org/drtshock/OvenException.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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() {
|
||||
try {
|
||||
return this.isPutIntoOven();
|
||||
} catch (OvenException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue