From: Mario Splivalo <mario.splivalo@mobart.hr>
To: pgsql-jdbc@postgresql.org
Subject: Catching postgres exceptions - functions returning error values?
Date: Wed, 30 Aug 2006 16:38:47 +0200
Message-ID: <1156948727.29660.24.camel@localhost.localdomain> (raw)
What would be the preffered way of catching postgres exceptions within
Java code?
For instance, I have an application where user types in database name
he/she wishes to connect to. So, when user enters the database name, I
try to connect to it. If that database does not exists, I'm thrown an
exception, something like this:
org.postgresql.util.PSQLException: Backend start-up failed:
org.postgresql.util.PSQLException: FATAL: database "testdb" does not
exist
Now, if the database server is unavailable, I get something like this:
org.postgresql.util.PSQLException: Connection refused. Check that the
hostname and port are correct and that the postmaster is accepting
TCP/IP connections.
I would like to know, in my code, what happened, and inform user
apropriatley, I don't want just to print the exception to the user.
I could parse the return from printStackTrace method, but that just
doesn't seem right.
Also, some of the functions need to return errorcode of some sort. If
the function is returning SETOF, I can't use OUT parametars. So, I'm
asking for a recomendation here.
I'm using postgres 8.1 with latest JDBC driver.
Thank you in advance,
Mario
--
Mario Splivalo
Mob-Art
mario.splivalo@mobart.hr
"I can do it quick, I can do it cheap, I can do it well. Pick any two."
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: mario.splivalo@mobart.hr
Subject: Re: Catching postgres exceptions - functions returning error values?
In-Reply-To: <1156948727.29660.24.camel@localhost.localdomain>
References: <1156948727.29660.24.camel@localhost.localdomain>
* 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