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 JohnHEmbretsen
Date Thu, 08 Nov 2007 13:31:57 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 JohnHEmbretsen:
http://wiki.apache.org/db-derby/UnwindExceptionChain

------------------------------------------------------------------------------
  SQLException supports a chaining model and Derby uses it when multiple exceptions are involved
or more context is needed than just the original exception. Typically the actual problem is
the last exception in the chain, so displaying the entire chain will make debugging issues
much easier. Here's an example of how to walk the chain.
  
  {{{
+ #!java numbers=off
  catch (SQLException e) {
-    do {
+     do {
-      System.out.println(e.toString());
-      e.printStackTrace(System.out);
+         System.out.println("\n----- SQLException -----");
+         System.out.println("  SQLState:   " + e.getSQLState());
+         System.out.println("  Error Code: " + e.getErrorCode());
+         System.out.println("  Message:    " + e.getMessage());
-      e = e.getNextException();
+         e = e.getNextException();
-    } while (e != null);
+     } while (e != null);
+     // for stack dumps, refer to derby.log or add
+     //e.printStackTrace(System.out); above
  } 
  }}}
  
@@ -23, +28 @@

  The idiom for printing all SQLExceptions and their causes would then look something like
this:
  
  {{{
+ #!java numbers=off
  catch(SQLException e) {
       do {
          System.out.println("SQLState:" + e.getSQLState());
@@ -34, +40 @@

              t = t.getCause();
          }
          e = e.getNextException();
-     } while (e !=null);
+     } while (e != null);
  }
  }}}
  

Mime
View raw message