db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Db-derby Wiki] Update of "UnwindExceptionChain" by DagWanvik
Date Wed, 15 Aug 2007 14:11:48 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Db-derby Wiki" for change notification.

The following page has been changed by DagWanvik:
http://wiki.apache.org/db-derby/UnwindExceptionChain

------------------------------------------------------------------------------
  } 
  }}}
  
+ With JDBC 4.0, causes are supported, cf. Lance Anderson's [http://weblogs.java.net/blog/lancea/archive/2006/02/index.html
blog] on this.
+ The idiom for printing all SQLExceptions and their causes would then look something like
this:
+ 
+ {{{
+ catch(SQLException e) {
+      do {
+         System.out.println("SQLState:" + e.getSQLState());
+         System.out.println("Error Code:" + e.getErrorCode());
+         System.out.println("Message:" + e.getMessage());
+         Throwable t = e.getCause();
+         while(t != null) {
+             System.out.println("Cause:" + t);
+             t = t.getCause();
+         }
+         e = e.getNextException();
+     } while (e !=null);
+ }}}
+ 
+ While more "correct" for JDBC 4.0, the latter idiom does not currently
+ give extra information in most cases, since Derby often wraps causes
+ in SQLException, to support showing root causes in earlier versions of
+ JDBC. That is, walking the chain via getNextException() would give you
+ causes for exceptions as well as more exceptions if present. This
+ "redundancy" may change in the future.
+ 
+ }
+ 
+ Inspecting `derby.log` for the stack dump of the error is often also
+ useful in understanding what's going on.
+ 

Mime
View raw message