Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Exception handling
Exception handling [message #908948] Thu, 06 September 2012 09:35 Go to next message
Andreas Bohnert is currently offline Andreas BohnertFriend
Messages: 2
Registered: September 2012
Junior Member
Hi everybody,

there is one thing about eclispelink which I never really found out:

how are you doing the exception handling properly?

for example:
the documentation explains that getSingleResult() throws NoResultException and NonUniqueResultException.
if I use the api in eclispe and try to surround getSingleResult with try/catch, there are actually no exception thrown.

the only thing I can do is specifiy a global exception handler which gives me at least the possibility to log the error. but there is no exception bubbeling up and I can respond if there is a problem (at least not on ejb level).

how are you this?
any help is highly appreciated!
Thanks,
andreas

Re: Exception handling [message #909062 is a reply to message #908948] Thu, 06 September 2012 13:19 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

getSingleResult() does throw these exceptions. They are RuntimeExceptions (as all exceptions in JPA), so you are not required to catch them, and may not see them in the throws clause.
They will be thrown if your query returns nothing, or multiple rows.


James : Wiki : Book : Blog : Twitter
Re: Exception handling [message #909434 is a reply to message #909062] Fri, 07 September 2012 06:13 Go to previous messageGo to next message
Andreas Bohnert is currently offline Andreas BohnertFriend
Messages: 2
Registered: September 2012
Junior Member
hi james,

thanks for quick response!

very strange. why they use runtime exceptions?
according to oracle:
"One Exception subclass, RuntimeException, is reserved for exceptions
that indicate incorrect use of an API"

maybe in case of getSingleResult it is debateable, but if they use
runtime exceptions for the entire jpa api I wonder why they change the
concept of using exceptions.

even in a enterprise environment where you may have managed transactions
they could have implement normal exceptions.

So, if you want to respond to issues which may happen on the database
side, you are supposed to catch the runtime exception, right?

andreas




James Sutherland schrieb:
> getSingleResult() does throw these exceptions. They are
> RuntimeExceptions (as all exceptions in JPA), so you are not required to
> catch them, and may not see them in the throws clause.
> They will be thrown if your query returns nothing, or multiple rows.
>
Re: Exception handling [message #911337 is a reply to message #909434] Tue, 11 September 2012 12:18 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Yes, you should catch the runtime exception if you wish to handle it.

James : Wiki : Book : Blog : Twitter
Previous Topic:How create JDBC connection in EcelipseLInk application
Next Topic:UUIDSequence
Goto Forum:
  


Current Time: Fri Dec 19 06:38:50 GMT 2014

Powered by FUDForum. Page generated in 0.03243 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software