Skip site navigation (1) Skip section navigation (2)

Re: PSQLException - How to Identify Type?

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Ryan Daniels <ryan(dot)daniels(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PSQLException - How to Identify Type?
Date: 2008-10-15 07:09:13
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
Ryan Daniels wrote:
> Hello,
> When I get a PSQLException, how do I identify which type it is? I need 
> to be able to distinguish which error occurred.

Have a look at the JDBC documentation, in particular the documentation 
for SQLException.

Note the getErrorCode() and getSQLState() members?

The error code is usually quite sufficient for program flow control and 
error handling decisions. See the PostgreSQL error code documentation:

Note that you can match error codes by class (the first byte) as well as 
by exact error code. As a result, you can easily do things like "Retry 
the transaction on all possibly tansient errors" in quite a generic way.

The documentation for PSQLException shows you how to get information 
from it, too:

it provdes getServerErrorMessage(), which returns about as much as you'd 
ever want to know:

Craig Ringer

In response to

pgsql-jdbc by date

Next:From: mark_addlemanDate: 2008-10-15 23:14:07
Subject: Re: COPY support in JDBC driver?
Previous:From: Ryan DanielsDate: 2008-10-15 05:01:12
Subject: PSQLException - How to Identify Type?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group