-1

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);
}
Durja
  • 637
  • 13
  • 20

2 Answers2

2

You should :

azro
  • 53,056
  • 7
  • 34
  • 70
0

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.

Somaiah Kumbera
  • 7,063
  • 4
  • 43
  • 44