Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2324S2#36 from yeozongyao/branch-zong…
Browse files Browse the repository at this point in the history
…yao-defensiveCoding

Exception handling
  • Loading branch information
yeozongyao authored Mar 21, 2024
2 parents 7e1fc6c + e36cb06 commit 90fbea3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/seedu/bookbuddy/BookList.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package seedu.bookbuddy;


import exceptions.BookNotFoundException;

import java.util.ArrayList;

/**
Expand Down Expand Up @@ -30,9 +32,9 @@ public int getSize(){
* @param index The index of the book to retrieve.
* @return The Book at the specified index.
*/
public Book getBook(int index) throws IndexOutOfBoundsException{
public Book getBook(int index) throws BookNotFoundException{
if (index < 0 || index > books.size()) {
throw new IndexOutOfBoundsException("Book index out of range.");
throw new BookNotFoundException("Book index out of range.");
}
assert books.get(index) != null : "Retrieved book should not be null";
return books.get(index);
Expand Down

0 comments on commit 90fbea3

Please sign in to comment.