< prev index next >

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

Print this page




 775         }
 776 
 777         void println(Object o) {
 778             printWriter.println(o);
 779         }
 780     }
 781 
 782     /**
 783      * Fills in the execution stack trace. This method records within this
 784      * {@code Throwable} object information about the current state of
 785      * the stack frames for the current thread.
 786      *
 787      * <p>If the stack trace of this {@code Throwable} {@linkplain
 788      * Throwable#Throwable(String, Throwable, boolean, boolean) is not
 789      * writable}, calling this method has no effect.
 790      *
 791      * @return  a reference to this {@code Throwable} instance.
 792      * @see     java.lang.Throwable#printStackTrace()
 793      */
 794     public synchronized Throwable fillInStackTrace() {





















 795         if (stackTrace != null ||
 796             backtrace != null /* Out of protocol state */ ) {
 797             fillInStackTrace(0);
 798             stackTrace = UNASSIGNED_STACK;
 799         }
 800         return this;
 801     }
 802 
 803     private native Throwable fillInStackTrace(int dummy);
 804 
 805     /**
 806      * Provides programmatic access to the stack trace information printed by
 807      * {@link #printStackTrace()}.  Returns an array of stack trace elements,
 808      * each representing one stack frame.  The zeroth element of the array
 809      * (assuming the array's length is non-zero) represents the top of the
 810      * stack, which is the last method invocation in the sequence.  Typically,
 811      * this is the point at which this throwable was created and thrown.
 812      * The last element of the array (assuming the array's length is non-zero)
 813      * represents the bottom of the stack, which is the first method invocation
 814      * in the sequence.
 815      *
 816      * <p>Some virtual machines may, under some circumstances, omit one
 817      * or more stack frames from the stack trace.  In the extreme case,
 818      * a virtual machine that has no stack trace information concerning
 819      * this throwable is permitted to return a zero-length array from this
 820      * method.  Generally speaking, the array returned by this method will
 821      * contain one element for every frame that would be printed by
 822      * {@code printStackTrace}.  Writes to the returned array do not
 823      * affect future calls to this method.




 775         }
 776 
 777         void println(Object o) {
 778             printWriter.println(o);
 779         }
 780     }
 781 
 782     /**
 783      * Fills in the execution stack trace. This method records within this
 784      * {@code Throwable} object information about the current state of
 785      * the stack frames for the current thread.
 786      *
 787      * <p>If the stack trace of this {@code Throwable} {@linkplain
 788      * Throwable#Throwable(String, Throwable, boolean, boolean) is not
 789      * writable}, calling this method has no effect.
 790      *
 791      * @return  a reference to this {@code Throwable} instance.
 792      * @see     java.lang.Throwable#printStackTrace()
 793      */
 794     public synchronized Throwable fillInStackTrace() {
 795         return fillInStackTrace(null);
 796     }
 797 
 798     /**
 799      * Fills in the execution stack trace. This method records within this
 800      * {@code Throwable} object information about the current state of
 801      * the stack frames for the current thread in the given {@link ContinuationScope}.
 802      * 
 803      * <p>If this method is called not inside a continuation with the given scope,
 804      * the entire thread stack is returned.
 805      *
 806      * <p>If the stack trace of this {@code Throwable} {@linkplain
 807      * Throwable#Throwable(String, Throwable, boolean, boolean) is not
 808      * writable}, calling this method has no effect.
 809      *
 810      * @param  scope The scope of the continuation whose stack we want to capture; 
 811      *               {@code null} for the entire thread stack.
 812      * @return  a reference to this {@code Throwable} instance.
 813      * @see     java.lang.Throwable#printStackTrace()
 814      */
 815     public synchronized Throwable fillInStackTrace(ContinuationScope scope) {
 816         if (stackTrace != null ||
 817             backtrace != null /* Out of protocol state */ ) {
 818             fillInStackTrace(scope, 0);
 819             stackTrace = UNASSIGNED_STACK;
 820         }
 821         return this;
 822     }
 823 
 824     private native Throwable fillInStackTrace(ContinuationScope scope, int dummy);
 825 
 826     /**
 827      * Provides programmatic access to the stack trace information printed by
 828      * {@link #printStackTrace()}.  Returns an array of stack trace elements,
 829      * each representing one stack frame.  The zeroth element of the array
 830      * (assuming the array's length is non-zero) represents the top of the
 831      * stack, which is the last method invocation in the sequence.  Typically,
 832      * this is the point at which this throwable was created and thrown.
 833      * The last element of the array (assuming the array's length is non-zero)
 834      * represents the bottom of the stack, which is the first method invocation
 835      * in the sequence.
 836      *
 837      * <p>Some virtual machines may, under some circumstances, omit one
 838      * or more stack frames from the stack trace.  In the extreme case,
 839      * a virtual machine that has no stack trace information concerning
 840      * this throwable is permitted to return a zero-length array from this
 841      * method.  Generally speaking, the array returned by this method will
 842      * contain one element for every frame that would be printed by
 843      * {@code printStackTrace}.  Writes to the returned array do not
 844      * affect future calls to this method.


< prev index next >