Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

FinderException

 
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?
 
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
 
ranger
Posts: 17346
11
Mac IntelliJ IDE 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
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic