Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FinderException

 
Nathan Huiras
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a Database Access Object class to retrieve data from a database. If I don't find an object in the database when trying to find it, should I use a FinderException, or an ObjectNotFoundException?
 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nathan,

FinderException is a super class of ObjectNotFoundException(ONFE), So if you catch FinderException, ONFE will itself be caught. but infact both are used in different scenarios.

FinderException is the exception you need to catch as it better suits your requirement.

Cheers,
Rahul
 
Nathan Huiras
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When would it be better to use an ObjectNotFoundException versus a FinderException and why?
 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nathan,

Hope this will help you.

FinderException- This exception indicates that an application error occurred (invalid arguments, etc.) while the container attempted to find the beans. Do not use this method to indicate that entities were not found. Multi-entity find methods return an empty collection if no entities were found; single-entity find methods throw an ObjectNotFoundException to indicate that no object was found.

ObjectNotFoundException - The ObjectNotFoundException is thrown from a single-entity find method to indicate that the container couldn't find the requested entity. This exception can be thrown by the container if the container is managing persistence, or it can be thrown explicitly by the bean developer in the ejbFind...() methods. This exception should not be thrown to indicate a business logic error (invalid arguments, etc.). Use the FinderException to indicate business logic errors in single-entity find methods. The ObjectNotFoundException is only thrown by single-entity find methods to indicate that the entity requested was not found. Find methods that return multiple entities should return an empty collection if nothing is found.

Cheers,
Rahul
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the JDBC forum. This forum is for Servlet questions only.

Thanks

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic