From e36cb061c3f610201355102a185d40f0b0924da7 Mon Sep 17 00:00:00 2001 From: Yeo Zong Yao Date: Thu, 21 Mar 2024 21:29:48 +0800 Subject: [PATCH] Exception handling --- src/main/java/seedu/bookbuddy/BookList.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/bookbuddy/BookList.java b/src/main/java/seedu/bookbuddy/BookList.java index e961181a31..cefa691112 100644 --- a/src/main/java/seedu/bookbuddy/BookList.java +++ b/src/main/java/seedu/bookbuddy/BookList.java @@ -1,6 +1,8 @@ package seedu.bookbuddy; +import exceptions.BookNotFoundException; + import java.util.ArrayList; /** @@ -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);