From: Oliver Jowett <oliver@opencloud.com>
To: Nico <nicohmail-postgresql@yahoo.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: PSQLException instead of java.net.SocketException
Date: Mon, 03 Jan 2005 12:05:09 +1300
Message-ID: <41D87E25.6000508@opencloud.com> (raw)
In-Reply-To: <cr8r9n$1v2p$1@news.hub.org>
References: <cr8r9n$1v2p$1@news.hub.org>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: oliver@opencloud.com, nicohmail-postgresql@yahoo.com
Subject: Re: PSQLException instead of java.net.SocketException
In-Reply-To: <41D87E25.6000508@opencloud.com>
References: <cr8r9n$1v2p$1@news.hub.org> <41D87E25.6000508@opencloud.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox