GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||
GeezerVison is showing www.tutorialspoint.com — Java StackTraceElement Class
Selected Reading
Java StackTraceElement ClassIntroductionThe Java StackTraceElement class 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. Class DeclarationFollowing is the declaration for java.lang.StackTraceElement class − public final class StackTraceElement
extends Object
implements Serializable
Class constructors
Class methods
Methods inheritedThis class inherits methods from the following classes −
Example: Getting Current Thread Class Name using StackTraceElementThe following example shows the usage of Java StackTraceElement getClassName() method. In this program, we've defined a function named function2() which gets the class name from StackTraceElement of current thread. Another function named function1() is used to instantiate the StackTraceElementDemo class and call the function2() method. In main method, we've called the function1() method and result is printed. package com.tutorialspoint;
public class StackTraceElementDemo {
// main method
public static void main(String[] args) {
// call function1() to invoke function2()
function1();
}
// function1() is to invoke function2()
// using StackTraceElementDemo object
public static void function1() {
new StackTraceElementDemo().function2();
}
// print the class name of current thread using StackTraceElement
public void function2() {
System.out.print("class name : ");
System.out.print(Thread.currentThread().getStackTrace()[1].
getClassName());
}
}
OutputLet us compile and run the above program, this will produce the following result − class name : com.tutorialspoint.StackTraceElementDemo Advertisements
| ||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |