Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9053771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:30:38+00:00 2026-06-16T13:30:38+00:00

Hi there I am learning OOP by writing a dummy Library management project in

  • 0

Hi there I am learning OOP by writing a dummy Library management project in Java.

In serachBook(), if book is found in ArrayList, it returns book object, if not found it throws custom exception BookNotFound.

Question 1: Should it just return null and check the returned value at calling code for null or throw custom exception BookNotFound.

Currently I believe BookNotFound is appropriate and am currently doing it. However I am finding one more difficulty: In addbook(), I first call searchBook() to see book already exist, if not it adds the book. However if book doesnt exist searchBook() throws BookNotFound.

Qestion 2: How should I handle this exception thrown by searchBook() in addBook(), since in order to addBook() to insert book in a list, BookNotFound exception must occur. So should I write empty Catch(BookNotFound e){} ?

What could be better OO practice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:30:39+00:00Added an answer on June 16, 2026 at 1:30 pm

    You should return null if it doesn’t find book and state it in method document,

    Exception throwing is costly operation also it is well suited in exceptional case (like book name you passed null in searchBook() method

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning Java and OOP, and have been doing the problems at Project Euler
I'm learning JavaScript and there's an example in the book I'm using that I
I am learning object orientated programming from the online Stanford courses there is a
I am learning Java OOP. My program downloads file via FTP. I want to
I'm learning Python OOP and trying to convert a Java class to a Python
I'm learning OOP in Java, but I'm not sure how to implement this reference
I am currently learning OOP for a project I'm working on (I'm in highschool
is there url for learning cake bake command. for example i want learn acl
I'm learning Scala and there is a thing that I can't find out about
Are there any good resources for learning C++ that a C# user could use,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.