X-Original-To: pgsql-jdbc-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 3BF129FB2F9 for ; Wed, 30 Aug 2006 11:39:20 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 32205-10 for ; Wed, 30 Aug 2006 11:39:12 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 43D459FB2F2 for ; Wed, 30 Aug 2006 11:39:12 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from pjetlic.mobart.hr (pjetlic.mobart.hr [80.80.51.10]) by svr4.postgresql.org (Postfix) with ESMTP id 13F285AF87E for ; Wed, 30 Aug 2006 14:39:11 +0000 (GMT) Received: from localhost (localhost.localdomain [127.0.0.1]) by pjetlic.mobart.hr (Postfix) with ESMTP id 718541743F for ; Wed, 30 Aug 2006 16:39:06 +0200 (CEST) Received: from pjetlic.mobart.hr ([127.0.0.1]) by localhost (pjetlic [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 27579-03-6 for ; Wed, 30 Aug 2006 16:38:47 +0200 (CEST) Received: from mike.mobart.hr (mike.mobart.hr [192.168.10.94]) (using SSLv3 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by pjetlic.mobart.hr (Postfix) with ESMTP id B513C12BD6 for ; Wed, 30 Aug 2006 16:38:47 +0200 (CEST) Subject: Catching postgres exceptions - functions returning error values? From: Mario Splivalo Reply-To: mario.splivalo@mobart.hr To: pgsql-jdbc@postgresql.org Content-Type: text/plain Organization: Mob-Art Date: Wed, 30 Aug 2006 16:38:47 +0200 Message-Id: <1156948727.29660.24.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by OpenSource AV+AS Mail Server X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.268 tagged_above=0 required=5 tests=AWL, SPF_SOFTFAIL X-Spam-Level: * X-Archive-Number: 200608/177 X-Sequence-Number: 15704 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."