< prev index next >

src/java.base/share/classes/java/lang/Throwable.java

Print this page




 676                 se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);
 677 
 678             // Print cause, if any
 679             Throwable ourCause = getCause();
 680             if (ourCause != null)
 681                 ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu);
 682         }
 683     }
 684 
 685     /**
 686      * Print our stack trace as an enclosed exception for the specified
 687      * stack trace.
 688      */
 689     private void printEnclosedStackTrace(PrintStreamOrWriter s,
 690                                          StackTraceElement[] enclosingTrace,
 691                                          String caption,
 692                                          String prefix,
 693                                          Set<Throwable> dejaVu) {
 694         assert Thread.holdsLock(s.lock());
 695         if (dejaVu.contains(this)) {
 696             s.println("\t[CIRCULAR REFERENCE:" + this + "]");
 697         } else {
 698             dejaVu.add(this);
 699             // Compute number of frames in common between this and enclosing trace
 700             StackTraceElement[] trace = getOurStackTrace();
 701             int m = trace.length - 1;
 702             int n = enclosingTrace.length - 1;
 703             while (m >= 0 && n >=0 && trace[m].equals(enclosingTrace[n])) {
 704                 m--; n--;
 705             }
 706             int framesInCommon = trace.length - 1 - m;
 707 
 708             // Print our stack trace
 709             s.println(prefix + caption + this);
 710             for (int i = 0; i <= m; i++)
 711                 s.println(prefix + "\tat " + trace[i]);
 712             if (framesInCommon != 0)
 713                 s.println(prefix + "\t... " + framesInCommon + " more");
 714 
 715             // Print suppressed exceptions, if any
 716             for (Throwable se : getSuppressed())




 676                 se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);
 677 
 678             // Print cause, if any
 679             Throwable ourCause = getCause();
 680             if (ourCause != null)
 681                 ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu);
 682         }
 683     }
 684 
 685     /**
 686      * Print our stack trace as an enclosed exception for the specified
 687      * stack trace.
 688      */
 689     private void printEnclosedStackTrace(PrintStreamOrWriter s,
 690                                          StackTraceElement[] enclosingTrace,
 691                                          String caption,
 692                                          String prefix,
 693                                          Set<Throwable> dejaVu) {
 694         assert Thread.holdsLock(s.lock());
 695         if (dejaVu.contains(this)) {
 696             s.println(prefix + caption + "[CIRCULAR REFERENCE: " + this + "]");
 697         } else {
 698             dejaVu.add(this);
 699             // Compute number of frames in common between this and enclosing trace
 700             StackTraceElement[] trace = getOurStackTrace();
 701             int m = trace.length - 1;
 702             int n = enclosingTrace.length - 1;
 703             while (m >= 0 && n >=0 && trace[m].equals(enclosingTrace[n])) {
 704                 m--; n--;
 705             }
 706             int framesInCommon = trace.length - 1 - m;
 707 
 708             // Print our stack trace
 709             s.println(prefix + caption + this);
 710             for (int i = 0; i <= m; i++)
 711                 s.println(prefix + "\tat " + trace[i]);
 712             if (framesInCommon != 0)
 713                 s.println(prefix + "\t... " + framesInCommon + " more");
 714 
 715             // Print suppressed exceptions, if any
 716             for (Throwable se : getSuppressed())


< prev index next >