db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian d'Heureuse (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-2181) StandardException.printStackTrace() does not print the nested exception (cause)
Date Fri, 15 Dec 2006 21:25:22 GMT
    [ http://issues.apache.org/jira/browse/DERBY-2181?page=comments#action_12458942 ] 
Christian d'Heureuse commented on DERBY-2181:

I was wrong.
My applications gets a org.apache.derby.impl.jdbc.EmbedSQLException and not a StandardException.
The StandardException is wrapped into the EmbedSQLException and the nested Exception can be
retrieved by calling SQLException.getNextException().

Now I'm using the following routine to produce the full stack trace:

private static String getExceptionStackTrace (Throwable e) {
   StringWriter stringWriter = new StringWriter();
   PrintWriter printWriter = new PrintWriter(stringWriter);
   e.printStackTrace (printWriter);
   if (e instanceof SQLException) {
      SQLException se = (SQLException)e;
      while (true) {
         se = se.getNextException();
         if (se == null) break;
         printWriter.print ("caused by: ");
         se.printStackTrace (printWriter); }}
   return stringWriter.toString(); }

There is nothing wrong with StandardException and I'm sorry for the unnecessary JIRA entry,
which should be closed.

The only question that remains is whether the chaining of SQLExceptions through SQLException.getNextException()
will be replaced in the future by chaining through Throwable.getCause().

> StandardException.printStackTrace() does not print the nested exception (cause)
> -------------------------------------------------------------------------------
>                 Key: DERBY-2181
>                 URL: http://issues.apache.org/jira/browse/DERBY-2181
>             Project: Derby
>          Issue Type: Bug
>    Affects Versions:
>         Environment: Java 1.5
>            Reporter: Christian d'Heureuse
> In my Servlet application, an I/O error occurred, but I couldn't see the error message
of the I/O error.
> At line 298 in StandardException.java, the I/O exception is packed into a StandardException:
>    throw StandardException.newException(
> When my Servlet catches the exception, it calls Throwable.printStackTrace() to generate
a detailed error message. The output of printStackTrace() does not list the nested I/O exception.
> In Java 1.5, Throwable.printStackTrace() calls getCause() to get the nested exception.
GetCause() returns null, because the cause has not been set.
> One solution could be to override Throwable.getCause() and initCause() in StandardException
to get and set the nested exception. There are already getNestedException() and setNestedException()
methods in StandardException which could be mapped to getCause() and initCause().
> Another solution could be to change the constructor
>    StandardException(String messageID, Throwable t, Object[] args)
> This constructor currently calls
>    super(messageID);
> Instead it could call
>    super(messageID,t);
> to pass the nested Exception.
> StandardException.setNestedException() could be changed to call Throwable.initCause().
But the API docs of initCause() state stat "This method can be called at most once". So it's
probably better to override getCause() and initCause().
> A problem might me that Throwable.getCause() and initCause() have been introduced in
Java 1.4. But if these methods are implemented in StandardException, they would be just normal
methods in Java 1.3 and overrides in Java >= 1.4.

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


View raw message