Eclipse not display warning if try catch is not present

M

Mirror

Hello,
can you help me ?

i write this:
sf = (SessionFactory) super
.servlet
.getServletContext()
.getAttribute(
HibernatePlugIn.SESSION_FACTORY_KEY);
hsession = sf.openSession();

the method signature is:
public org.hibernate.classic.Session openSession() throws
HibernateException;

Why eclipse not say that a try-catch block is missing ?

Thank's
Giulio
 
V

visionset

the method signature is:
public org.hibernate.classic.Session openSession() throws
HibernateException;

Why eclipse not say that a try-catch block is missing ?

Because it is a RuntimeException
 
U

usenetuser

Hello,
can you help me ?

i write this:
sf = (SessionFactory) super
.servlet
.getServletContext()
.getAttribute(
HibernatePlugIn.SESSION_FACTORY_KEY);
hsession = sf.openSession();

the method signature is:
public org.hibernate.classic.Session openSession() throws
HibernateException;

Why eclipse not say that a try-catch block is missing ?

Thank's
Giulio

HibernateException inherits from RuntimeException... that's why. You
can still catch it if you want to, but you don't have to.
 
J

Jason Cavett

HibernateException inherits from RuntimeException... that's why. You
can still catch it if you want to, but you don't have to.- Hide quoted text -

- Show quoted text -

....and...from what I've learned about RuntimeExceptions, you shouldn't
really catch them anyway. If you're getting a RuntimeException you
have a deeper problem that needs fixed.
 
U

Uwe Plonus

Jason said:
...and...from what I've learned about RuntimeExceptions, you shouldn't
really catch them anyway. If you're getting a RuntimeException you
have a deeper problem that needs fixed.

Which is not true for HibernateException. In former versions of
hibernate it was not a RuntimeException. I don't know exactly why they
changed that but in the case of a HibernateException there are many ways
to continue.

Also other RuntimeExceptions are worth catching. Often you have the
possibility to continue.

Another thing are Errors. They are not worth of catching because you
can't do anything useful in case of an Error.

Uwe
 
O

Oliver Wong

Uwe Plonus said:
Which is not true for HibernateException. In former versions of
hibernate it was not a RuntimeException. I don't know exactly why they
changed that but in the case of a HibernateException there are many ways
to continue.

Also other RuntimeExceptions are worth catching. Often you have the
possibility to continue.

Another thing are Errors. They are not worth of catching because you
can't do anything useful in case of an Error.

Unless, of course, the people at Hibernate decide to change
HibernateException so that it no longer subclasses (Runtime)Exception, but
Error instead. In which case, you should catch that error, as there *is*
something useful you can do with it.

In other words, forget the dogma. Catch an throwable if it makes sense
to do so, and don't catch it if it doesn't make sense to do so.

- Oliver
 
J

Jason Cavett

Unless, of course, the people at Hibernate decide to change
HibernateException so that it no longer subclasses (Runtime)Exception, but
Error instead. In which case, you should catch that error, as there *is*
something useful you can do with it.

In other words, forget the dogma. Catch an throwable if it makes sense
to do so, and don't catch it if it doesn't make sense to do so.

- Oliver- Hide quoted text -

- Show quoted text -

Good advice. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top