From: | Oliver Jowett <oliver(at)opencloud(dot)com> |
---|---|
To: | Nico <nicohmail-postgresql(at)yahoo(dot)com> |
Cc: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: PSQLException instead of java.net.SocketException |
Date: | 2005-01-02 23:05:09 |
Message-ID: | 41D87E25.6000508@opencloud.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Nico wrote:
> My best guess is the exception was
> catched and a PSQLException was thrown in the catch block.
Yes, this is exactly what's happening. In general the driver will throw
a SQLException for all errors, including connection-level problems.
> I already have a
> catch block for PSQLException which is designed to warn me for SQL syntax
> errors, not socket exceptions. So I want to make an additional catch block
> for a java.net.SocketException. However I don't know how. Can someone please
> help me here?
You probably want to look at SQLException.getSQLState(). That gives a
somewhat standardized string that describes the error in more detail.
The driver passes through error codes received from the server directly,
and synthesizes appropriate error codes in some other cases (e.g.
connection failure).
In your case you want to look for all error codes starting with "08"
("Connection Exception"). See
http://www.postgresql.org/docs/current/static/errcodes-appendix.html for
a list of codes.
You could also do it by looking at the nested exception of the
SQLException, but that's not standard and isn't guaranteed to work; it's
really there to give extra information to a human, not for programmatic
logic.
-O
From | Date | Subject | |
---|---|---|---|
Next Message | Cameron Braid | 2005-01-03 12:45:02 | unsubscribe |
Previous Message | Dave Cramer | 2005-01-02 13:20:51 | Re: PSQLException instead of java.net.SocketException |