I have a question on what exception to throw when the passed in object is not in an array list.
public void deleteReview(Review review) {
if(!reviews.contains(review)) {
throw exception here..
}
reviews.remove(review);
}
I have a question on what exception to throw when the passed in object is not in an array list.
public void deleteReview(Review review) {
if(!reviews.contains(review)) {
throw exception here..
}
reviews.remove(review);
}
You should :
Exception
: How to create custom exceptions in Java ?
IllegalArgumentException
: Thrown to indicate that a method has been passed an illegal or inappropriate argument.NoSuchElementException
: Thrown by various accessor methods to indicate that the element being requested does not exist.This seems like a business case. Its not really a case for an exception. It just wasn't found. You can just ignore the case.
However, if you really want to throw an exception, you could try NoSuchElementException or even better create your own class that extends Exception and throw that.