• Dear Guest, Please do NOT forget to join our JAVA JOBS (ONLY) FACEBOOK GROUP to be aware of latest JAVA openings, and you may also post any JAVA related queries/jobs.

How to Access Stack Trace Information ?

A Stack Trace provides information on the execution history of the current thread and lists the names of the classes and methods that were called at the point when the Exception occurred.

Example :

- The following code shows how to call the getStackTrace method on the Exception object.

catch (Exception cause) {
StackTraceElement elements[] = cause.getStackTrace();
for (int i = 0, n = elements.length; i < n; i++) {
System.err.println(elements.getFileName() + ":"
+ elements.getLineNumber()
+ ">> "
+ elements.getMethodName() + "()");
String classs = new Throwable().fillInStackTrace().getStackTrace()[1].getClassName();
String caller = new Throwable().fillInStackTrace().getStackTrace()[1].getMethodName();
int line = new Throwable().fillInStackTrace().getStackTrace()[12].getLineNumber();
String file = new Throwable().fillInStackTrace().getStackTrace()[1].getFileName();
The StackTrace acreage lists adjustment calls in about-face archival order, that is, the best contempo adjustment alarm is declared first, and one band of assemblage trace advice is listed for anniversary adjustment alarm on the stack. However, the StackTrace acreage ability not address as abounding adjustment calls as accepted due to cipher transformations that action during optimization.