Exception handling [message #908948] |
Thu, 06 September 2012 05:35  |
Eclipse User |
|
|
|
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 #909434 is a reply to message #909062] |
Fri, 07 September 2012 02:13   |
Eclipse User |
|
|
|
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.
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03857 seconds