-
Is right a findermethod throws an exception? (2 messages)
- Posted by: Edson Alves Pereira
- Posted on: November 04 2006 09:42 EST
Hello dudes, there's something bother me a lot these days, why i need to throw a FinderException if it cannot find any register in the database that represents the primaryKey? Why not just to return a NULL primaryKey object? Regards, lottalavaThreaded Messages (2)
- Re: Is right a findermethod throws an exception? by arijit dey on November 06 2006 00:38 EST
- Re: Is right a findermethod throws an exception? by AMulya Mishra on November 08 2006 05:45 EST
-
Re: Is right a findermethod throws an exception?[ Go to top ]
- Posted by: arijit dey
- Posted on: November 06 2006 00:38 EST
- in response to Edson Alves Pereira
Well! first of all! Exceptions are not your enemies, they are like symptoms that tell you that you are going to fall sick.If you have a finder Exception then you know that the key does not exist in the database, so you think of something else to handle the situation, returning null won't do because database won't allow null as keys and your are returning null as a key to indicate that its not there and may be in future you try to do something with it and get NullPointerException. Its not about returning null, its about telling that it din't find your key.Now its up to you what you want to do return null or your name. cheers, http://www.javaicillusion.blogspot.com/ -
Re: Is right a findermethod throws an exception?[ Go to top ]
- Posted by: AMulya Mishra
- Posted on: November 08 2006 05:45 EST
- in response to Edson Alves Pereira
More to that..J2EE follows some standards and specifications. Its the standard that the FinderException exception must be included in the throws clause of every findMETHOD(...) method of an entity Bean's home interface. The exception is used as a standard application-level exception to report a failure to find the requested EJB object(s).Based on these specific exception, container takes appropriate actions and helps you to guide properly, else on returning NULL, at what point down the line, your application would crash, nobody knows!!