tags:

views:

53

answers:

2

Hi,

On server's side I use hibernate to communicate with database. However, if the database is offline I can't catch any exception related with the connection. What's more, on client's site where gwt is used, onFailure(Throwable caught) function is executed, but caught.printStackTrace(); prints nothing. I want gwt to inform a user that the database is currently unavailable, but as you can read I can't catch any exception which can help me to do that. Any ideas?

update:

e.g.

public class HibernateUtil
{
    private static final SessionFactory sessionFactory;

    static {
        try {
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}

...

Session session = null;
try
{
   session = HibernateUtil.getSessionFactory().openSession();
} catch (Throwable ex) {
   System.err.println("Initial SessionFactory creation failed." + ex);
}

In both cases no exception is catched if the database is offline, so I'm not able to send a message about the problem with connection to the client

Thanks in advance

A: 

You can catch the Exception server-side, and then pass it down to the callback in your DTO as a successful request. Add an "isError" flag to the DTO, and in the onSuccess() method in the client check the flag and process accordingly. In fact, you can call onFailure() from on Success() with the downloaded Exception. You may have to make the Exception serializable.

Glenn
I'm sorry but this is not what I mean, see my update
Does this question have anything to do with GWT?
Glenn
maybe a little bit cause onFailure(Throwable caught) is executed but caught.printStackTrace(); prints nothing, I've changed the topic
A: 

You have to add "throws Exception" for your ServiceAsync -interfaces and be sure that the exceptions can be serializable. I recommend catching the db-exceptions on the serverside and then throw your own exceptions.

pathed
"I recommend catching the db-exceptions on the serverside and then throw your own exceptions." - but here's the problem, I can't catch them. As you can see in my example, catching Throwable doesn't work