X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 277DE3A2CF4 for ; Sun, 2 Jan 2005 23:05:24 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25748-09 for ; Sun, 2 Jan 2005 23:05:14 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 4CDAB3A2C83 for ; Sun, 2 Jan 2005 23:05:14 +0000 (GMT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1ClEmd-0003ze-00; Mon, 03 Jan 2005 12:05:11 +1300 Message-ID: <41D87E25.6000508@opencloud.com> Date: Mon, 03 Jan 2005 12:05:09 +1300 From: Oliver Jowett User-Agent: Mozilla Thunderbird 1.0 (X11/20041228) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Nico Cc: pgsql-jdbc@postgresql.org Subject: Re: PSQLException instead of java.net.SocketException References: In-Reply-To: X-Enigmail-Version: 0.89.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200501/3 X-Sequence-Number: 11883 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