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 A956D9FA5CE for ; Wed, 30 Aug 2006 13:31:45 -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 51965-01 for ; Wed, 30 Aug 2006 13:31:41 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id A5B139FA4A5 for ; Wed, 30 Aug 2006 13:31:41 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1GISwi-0003pN-As for pgsql-jdbc@postgresql.org; Wed, 30 Aug 2006 18:29:44 +0200 Received: from 83.145.96.118 ([83.145.96.118]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 30 Aug 2006 18:29:44 +0200 Received: from Marc.Herbert by 83.145.96.118 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 30 Aug 2006 18:29:44 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Marc Herbert Subject: Re: Catching postgres exceptions - functions returning error values? Date: Wed, 30 Aug 2006 18:27:40 +0200 Lines: 33 Message-ID: References: <1156948727.29660.24.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 83.145.96.118 User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.4 (Jumbo Shrimp, linux) Cancel-Lock: sha1:lGawIFOMerhSP7JaralmTqcoBxo= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.633 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, RCVD_NUMERIC_HELO, SPF_HELO_PASS, SPF_PASS X-Spam-Level: * X-Archive-Number: 200608/178 X-Sequence-Number: 15705 Mario Splivalo writes: > 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. What would like to substitute to the above message for instance? Is this just a language issue? > 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. Maybe you want to use the SQLState http://www.postgresql.org/docs/8.1/interactive/errcodes-appendix.html http://www.easysoft.com/developer/interfaces/odbc/sqlstate_status_return_codes.html http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcodbc_error_codes.asp http://www.opengroup.org/bookstore/catalog/c451.htm (appendix A) http://www.opengroup.org/bookstore/catalog/c449.htm (appendix B)