Eclipse not display warning if try catch is not present

Discussion in 'Java' started by Mirror, Apr 5, 2007.

  1. Mirror

    Mirror Guest

    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
     
    Mirror, Apr 5, 2007
    #1
    1. Advertisements

  2. Mirror

    visionset Guest

    Because it is a RuntimeException
     
    visionset, Apr 5, 2007
    #2
    1. Advertisements

  3. Mirror

    usenetuser Guest

    HibernateException inherits from RuntimeException... that's why. You
    can still catch it if you want to, but you don't have to.
     
    usenetuser, Apr 5, 2007
    #3
  4. Mirror

    Jason Cavett Guest

    ....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.
     
    Jason Cavett, Apr 5, 2007
    #4
  5. Mirror

    Uwe Plonus Guest

    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
     
    Uwe Plonus, Apr 5, 2007
    #5
  6. Mirror

    Oliver Wong Guest

    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
     
    Oliver Wong, Apr 5, 2007
    #6
  7. Mirror

    Jason Cavett Guest

    Good advice. Thanks.
     
    Jason Cavett, Apr 5, 2007
    #7
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.