Methods Summary |
---|
private static int | countDuplicates(java.lang.StackTraceElement[] currentStack, java.lang.StackTraceElement[] parentStack)Counts the number of duplicate stack frames, starting from the
end of the stack.
int duplicates = 0;
int parentIndex = parentStack.length;
for (int i = currentStack.length; --i >= 0 && --parentIndex >= 0;) {
StackTraceElement parentFrame = parentStack[parentIndex];
if (parentFrame.equals(currentStack[i])) {
duplicates++;
} else {
break;
}
}
return duplicates;
|
public java.lang.Throwable | fillInStackTrace()Records the stack trace from the point where this method has been called
to this {@code Throwable}. The method is public so that code which
catches a {@code Throwable} and then re-throws it can adjust the stack
trace to represent the location where the exception was re-thrown.
// Fill in the intermediate representation
stackState = nativeFillInStackTrace();
// Mark the full representation as empty
stackTrace = null;
return this;
|
public java.lang.Throwable | getCause()Returns the cause of this {@code Throwable}, or {@code null} if there is
no cause.
if (cause == this) {
return null;
}
return cause;
|
private java.lang.StackTraceElement[] | getInternalStackTrace()Returns an array of StackTraceElement. Each StackTraceElement
represents a entry on the stack.
if (stackTrace == null) {
// BEGIN android-changed
stackTrace = nativeGetStackTrace(stackState);
stackState = null; // Clean up intermediate representation
// END android-changed
}
return stackTrace;
|
public java.lang.String | getLocalizedMessage()Returns the extra information message which was provided when this
{@code Throwable} was created. Returns {@code null} if no message was
provided at creation time. Subclasses may override this method to return
localized text for the message. The Android reference implementation
returns the unlocalized detail message.
return getMessage();
|
public java.lang.String | getMessage()Returns the extra information message which was provided when this
{@code Throwable} was created. Returns {@code null} if no message was
provided at creation time.
return detailMessage;
|
public java.lang.StackTraceElement[] | getStackTrace()Returns the array of stack trace elements of this {@code Throwable}. Each
{@code StackTraceElement} represents an entry in the call stack. The
element at position 0 is the top of the stack, that is, the stack frame
where this {@code Throwable} is thrown.
return getInternalStackTrace().clone();
|
public java.lang.Throwable | initCause(java.lang.Throwable throwable)Initializes the cause of this {@code Throwable}. The cause can only be
initialized once.
// BEGIN android-note
// removed synchronized modifier
// END android-note
if (cause == this) {
if (throwable != this) {
cause = throwable;
return this;
}
throw new IllegalArgumentException("Cause cannot be the receiver");
}
throw new IllegalStateException("Cause already initialized");
|
private static native java.lang.Object | nativeFillInStackTrace()
|
private static native java.lang.StackTraceElement[] | nativeGetStackTrace(java.lang.Object stackState)
|
public void | printStackTrace()Writes a printable representation of this {@code Throwable}'s stack trace
to the {@code System.err} stream.
printStackTrace(System.err);
|
public void | printStackTrace(java.io.PrintStream err)Writes a printable representation of this {@code Throwable}'s stack trace
to the specified print stream. If the {@code Throwable} contains a
{@link #getCause() cause}, the method will be invoked recursively for
the nested {@code Throwable}.
err.println(toString());
// Don't use getStackTrace() as it calls clone()
// Get stackTrace, in case stackTrace is reassigned
StackTraceElement[] stack = getInternalStackTrace();
for (java.lang.StackTraceElement element : stack) {
err.println("\tat " + element);
}
StackTraceElement[] parentStack = stack;
Throwable throwable = getCause();
while (throwable != null) {
err.print("Caused by: ");
err.println(throwable);
StackTraceElement[] currentStack = throwable.getInternalStackTrace();
int duplicates = countDuplicates(currentStack, parentStack);
for (int i = 0; i < currentStack.length - duplicates; i++) {
err.println("\tat " + currentStack[i]);
}
if (duplicates > 0) {
err.println("\t... " + duplicates + " more");
}
parentStack = currentStack;
throwable = throwable.getCause();
}
|
public void | printStackTrace(java.io.PrintWriter err)Writes a printable representation of this {@code Throwable}'s stack trace
to the specified print writer. If the {@code Throwable} contains a
{@link #getCause() cause}, the method will be invoked recursively for the
nested {@code Throwable}.
err.println(toString());
// Don't use getStackTrace() as it calls clone()
// Get stackTrace, in case stackTrace is reassigned
StackTraceElement[] stack = getInternalStackTrace();
for (java.lang.StackTraceElement element : stack) {
err.println("\tat " + element);
}
StackTraceElement[] parentStack = stack;
Throwable throwable = getCause();
while (throwable != null) {
err.print("Caused by: ");
err.println(throwable);
StackTraceElement[] currentStack = throwable.getInternalStackTrace();
int duplicates = countDuplicates(currentStack, parentStack);
for (int i = 0; i < currentStack.length - duplicates; i++) {
err.println("\tat " + currentStack[i]);
}
if (duplicates > 0) {
err.println("\t... " + duplicates + " more");
}
parentStack = currentStack;
throwable = throwable.getCause();
}
|
public void | setStackTrace(java.lang.StackTraceElement[] trace)Sets the array of stack trace elements. Each {@code StackTraceElement}
represents an entry in the call stack. A copy of the specified array is
stored in this {@code Throwable}. will be returned by {@code
getStackTrace()} and printed by {@code printStackTrace()}.
StackTraceElement[] newTrace = trace.clone();
for (java.lang.StackTraceElement element : newTrace) {
if (element == null) {
throw new NullPointerException();
}
}
stackTrace = newTrace;
|
public java.lang.String | toString()
String msg = getLocalizedMessage();
String name = getClass().getName();
if (msg == null) {
return name;
}
return new StringBuffer(name.length() + 2 + msg.length()).append(name).append(": ")
.append(msg).toString();
|
private void | writeObject(java.io.ObjectOutputStream s)
// ensure the stackTrace field is initialized
getInternalStackTrace();
s.defaultWriteObject();
|