![]() |
VOOZH | about |
An element in a stack trace, as returned by Throwable.getStackTrace(). Each element represents a single stack frame. All stack frames except for the one at the top of the stack represent a method invocation. The frame at the top of the stack represents the execution point at which the stack trace was generated.
This class describes single stack frame, which is an individual element of a stack trace when an exception occur.
Constructor: Creates a stack trace element representing the specified execution point.
StackTraceElement(String declaringClass, String methodName, String fileName, int lineNumber)
Parameters:
Throws: NullPointerException - if declaringClass or methodName is null.
Methods:
1. boolean equals(ob): Returns try if the invoking StackTraceElement is as the one passed in ob. Otherwise it returns false.
Syntax: public boolean equals(ob) Returns: true if the specified object is another StackTraceElement instance representing the same execution point as this instance. Exception: NA
Output:
true
2. String getClassName(): Returns the class name of the execution point described by the invoking StackTraceElement.
Syntax: public String getClassName(). Returns: the fully qualified name of the Class containing the execution point represented by this stack trace element. Exception: NA.
Output:
Class name of each thread involved: java.lang.Thread StackTraceElementDemo
3. String getFileName(): Returns the file name of the execution point described by the invoking StackTraceElement.
Syntax: public String getFileName(). Returns: the name of the file containing the execution point represented by this stack trace element, or null if this information is unavailable. Exception: NA.
Output:
file name: Thread.java StackTraceElementDemo.java
4. int getLineNumber(): Returns the source-code line number of the execution point described by the invoking StackTraceElement. In some situation the line number will not be available, in which case a negative value is returned.
Syntax: public int getLineNumber(). Returns: the line number of the source line containing the execution point represented by this stack trace element, or a negative number if this information is unavailable. Exception: NA.
Output:
line number: 1556 10
5. String getMethodName(): Returns the method name of the execution point described by the invoking StackTraceElement.
Syntax: public String getMethodName(). Returns: the name of the method containing the execution point represented by this stack trace element. Exception: NA.
Output:
method name: getStackTrace main
6. int hashCode(): Returns the hash code of the invoking StackTraceElement.
Syntax: public int hashCode(). Returns: a hash code value for this object. Exception: NA.
Output:
hash code: -1225537245 -1314176653
7. boolean isNativeMethod(): Returns true if the invoking StackTraceElement describes a native method. Otherwise returns false.
Syntax: public boolean isNativeMethod(). Returns: true if the method containing the execution point represented by this stack trace element is a native method. Exception: NA.
Output:
false false
8. String toString(): Returns the String equivalent of the invoking sequence.
Syntax: public String toString(). Returns: a string representation of the object. Exception: NA.
Output:
String equivalent: java.lang.Thread.getStackTrace StackTraceElementDemo.main