0

I am working an application with Java, Hibernate and Postgres. The point of my question is the pass of throws because I don't catch Exception generated, ¿What I must correct?

public void seleccionarEquipo() throws Exception {
    try{
         this.integrantes = consultarIntegrantes();
    }catch(Exception e){
        System.out.println("{ERROR: " + e.toString() + "}");
    }
}

public List<Usuario> consultarIntegrantes() throws Exception {
    System.out.println("calling...");
    List<Usuario> usuarios = new ArrayList<Usuario>();
    Session session = NewHibernateUtil.getSessionFactory().openSession();
    Transaction transaction = session.beginTransaction();
    try {
        System.out.println("try...");
        Query query = session.createQuery("Anything");
        usuarios = query.list();
    } catch (Exception e) {
        System.out.println("error detected");
        throw e;
    }finally{
        transaction.commit();
        session.close();
        return usuarios;
    }
}

Output:

Info:   calling...
Info:   try...
Info:   error detected

My application doesn't execute: System.out.println("{ERROR: " + e.toString() + "}");. What I do?

Thank you!

  • Exceptions aren't functions. I take it you're coming from javascript? – byxor Sep 07 '16 at 18:38
  • Your exception is suppressed because you're returning in the `finally` block. Move `return usuarios;` to the end of the method so it only gets called in normal execution. – shmosel Sep 07 '16 at 18:43
  • Thank you shmosel. I will add a conditional for pass my exception. Or you recommend me another way? – Juan Camacho Sep 07 '16 at 18:47
  • 1
    @JuanCamacho No. Don't return from inside finally! Read the duplicate, I didn't mark it as such for fun. – Kayaman Sep 07 '16 at 18:49

0 Answers0