[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1233
  • Last Modified:

override printstacktrace

I am getting an exception in when running my program in eclipse. The entire trace is not shown. It displays some of the lines, but then is stays "and 12 more lines"
mtamonkey said that this issue was reported as a BUG to sun.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4775147
It's not something that they'll FIX, but they do list the customer's workaround which was to override the printstacktrace function.

The exception class is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
I should create my own CommunicationsException?

package com.mycompany.exceptions;

public class CommunicationsException {

public void printStackTrace(PrintWriter s) {
  // what goes here?
}
 
}
0
allelopath
Asked:
allelopath
3 Solutions
 
CEHJCommented:
0
 
allelopathAuthor Commented:
I'm not following you... i have this:

try {
    connection = DriverManager.getConnection(url, user, password);
    statement = connection.createStatement();
} catch (SQLException e) {
     e.printStackTrace();
     System.exit(-1);
}

What do I do?
0
 
CEHJCommented:
Instead of

>> e.printStackTrace();

Try

for (StackTraceElement ste : e.getStackTrace()) {
      System.err.println(e);
}      
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
Sorry

      System.err.println(ste);
0
 
mkatmonkeyCommented:
Here's an example. Sorry for not including it in my last answer.

public void printStackTrace(PrintWriter result) {
          result.println("\n Stack: ");
          result.println(this.toString());
          printStack( result);
          //add each element of the stack trace
          while (getCause()!=null){
                Throwable cause = getCause();
                result.append("Caused by: ");
                printStack(cause, result );
          }
          return result.toString();
}

private void printStack(Throwable cause, PrintWriter result){
          final List<StackTraceElement> traceElements = Arrays.asList(
                    cause.getStackTrace()
                 );
           for (StackTraceElement element : traceElements ){
                       result.println("    "+element);
           }              
 }
0
 
CEHJCommented:
Yes, but there's no good reason to create a List from the StackTraceElement[]
0
 
Tomas Helgi JohannssonCommented:
  Hi!

Here is several examples on Exceptions
http://www.java2s.com/Code/Java/Language-Basics/Exceptions.htm

Regards,
   Tomas Helgi
0
 
CEHJCommented:
:-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now