001package com.hfg.sql.jdbc; 002 003 004import java.sql.SQLException; 005 006//------------------------------------------------------------------------------ 007/** 008 Indicates an exception during a JDBC operation. 009 <div> 010 @author J. Alex Taylor, hairyfatguy.com 011 </div> 012 */ 013//------------------------------------------------------------------------------ 014// com.hfg XML/HTML Coding Library 015// 016// This library is free software; you can redistribute it and/or 017// modify it under the terms of the GNU Lesser General Public 018// License as published by the Free Software Foundation; either 019// version 2.1 of the License, or (at your option) any later version. 020// 021// This library is distributed in the hope that it will be useful, 022// but WITHOUT ANY WARRANTY; without even the implied warranty of 023// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 024// Lesser General Public License for more details. 025// 026// You should have received a copy of the GNU Lesser General Public 027// License along with this library; if not, write to the Free Software 028// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 029// 030// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 031// jataylor@hairyfatguy.com 032//------------------------------------------------------------------------------ 033 034public class JDBCException extends RuntimeException 035{ 036 //--------------------------------------------------------------------------- 037 public JDBCException() 038 { 039 super(); 040 } 041 042 //--------------------------------------------------------------------------- 043 public JDBCException(String inMessage) 044 { 045 super(inMessage); 046 } 047 048 //--------------------------------------------------------------------------- 049 public JDBCException(String inMessage, SQLException inException) 050 { 051 super(inMessage, createNewSQLException(inException)); 052 } 053 054 //--------------------------------------------------------------------------- 055 public JDBCException(String inMessage, Throwable inException) 056 { 057 super(inMessage, inException); 058 } 059 060 //--------------------------------------------------------------------------- 061 public JDBCException(SQLException inException) 062 { 063 super(createNewSQLException(inException)); 064 } 065 066 //--------------------------------------------------------------------------- 067 public JDBCException(Throwable inException) 068 { 069 super(inException); 070 } 071 072 //--------------------------------------------------------------------------- 073 // There might be a better way to handle this, but I'm trying to better expose 074 // the underlying nextException in the stacktrace. 075 private static SQLException createNewSQLException(SQLException inException) 076 { 077 SQLException exception = inException; 078 if (inException.getNextException() != null) 079 { 080 String msg = inException.getMessage(); 081 int index; 082 if ((index = msg.indexOf("Call getNextException to see the cause.")) > 0) 083 { 084 msg = msg.substring(0, index).trim(); 085 } 086 087 exception = new SQLException(msg, inException.getNextException()); 088 exception.setStackTrace(inException.getStackTrace()); 089 } 090 091 return exception; 092 } 093 094}