An element in a stack trace, as returned byThrowable.getStackTrace(). Each element represents a single stack frame.All stack frames except for the one at the top of the stack representa method invocation. The frame at the top of the stack represents theexecution point at which the stack trace was generated. Typically,this is the point at which the throwable corresponding to the stack tracewas created.
public StackTraceElement(String declaringClass,String methodName,String fileName,int lineNumber)
Creates a stack trace element representing the specified executionpoint.
Parameters:
declaringClass- the fully qualified name of the class containingthe execution point represented by the stack trace element
methodName- the name of the method containing the execution pointrepresented by the stack trace element
fileName- the name of the file containing the execution pointrepresented by the stack trace element, ornullifthis information is unavailable
lineNumber- the line number of the source line containing theexecution point represented by this stack trace element, ora negative number if this information is unavailable. A valueof -2 indicates that the method containing the execution pointis a native method
Returns the name of the source file containing the execution pointrepresented by this stack trace element. Generally, this correspondsto theSourceFileattribute of the relevantclassfile (as perThe Java Virtual Machine Specification, Section4.7.7). In some systems, the name may refer to some source code unitother than a file, such as an entry in source repository.
Returns:
the name of the file containing the execution pointrepresented by this stack trace element, ornullifthis information is unavailable.
getLineNumber
public int getLineNumber()
Returns the line number of the source line containing the executionpoint represented by this stack trace element. Generally, this isderived from theLineNumberTableattribute of the relevantclassfile (as perThe Java Virtual MachineSpecification, Section 4.7.8).
Returns:
the line number of the source line containing the executionpoint represented by this stack trace element, or a negativenumber if this information is unavailable.
Returns the name of the method containing the execution pointrepresented by this stack trace element. If the execution point iscontained in an instance or class initializer, this method will returnthe appropriatespecial method name,<init>or<clinit>, as per Section 3.9 ofThe Java VirtualMachine Specification.
Returns:
the name of the method containing the execution pointrepresented by this stack trace element.
isNativeMethod
public boolean isNativeMethod()
Returns true if the method containing the execution pointrepresented by this stack trace element is a native method.
Returns:
trueif the method containing the execution pointrepresented by this stack trace element is a native method.
Returns a string representation of this stack trace element. Theformat of this string depends on the implementation, but the followingexamples may be regarded as typical:
"MyClass.mash(MyClass.java:9)"- Here,"MyClass"is thefully-qualified nameof the class containing theexecution point represented by this stack trace element,"mash"is the name of the method containing the executionpoint,"MyClass.java"is the source file containing theexecution point, and"9"is the line number of the sourceline containing the execution point.
"MyClass.mash(MyClass.java)"- As above, but the linenumber is unavailable.
"MyClass.mash(Unknown Source)"- As above, but neitherthe file name nor the line number are available.
"MyClass.mash(Native Method)"- As above, but neitherthe file name nor the line number are available, and the methodcontaining the execution point is known to be a native method.
Returns true if the specified object is anotherStackTraceElementinstance representing the same executionpoint as this instance. Two stack trace elementsaandbare equal if and only if: