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?
When would it be better to use an ObjectNotFoundException versus a FinderException and why?
Joined: Aug 03, 2002
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.