CodeGym /Java-Kurse /Java Syntax /Stacktrace anzeigen – Übung

Stacktrace anzeigen – Übung

Java Syntax
Level 9 , Lektion 2
Verfügbar

„Hi, Amigo!“

„Hi, Diego!“

„Hier ist eine kleine Aufgabe zum Anzeigen des Stacktrace.“

Kommentare (3)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Tibor Thurnay Level 10, Karlsruhe, Germany
22 Oktober 2024
didn't check correctly if i just used System.out.println( element.getClassname()...)
Christof Level 16
30 Januar 2021
Hello, can someone explan me whats the meaning of the [2] in this code? Thread.currentThread().getStackTrace()[2].getMethodName();
Daniel Ritter Level 17, Augsburg, Deutschland
17 April 2021
Assuming we're in method2(), called by method1(): Thread.currentThread().getStackTrace() returns an array with StackTraceElements. The first element in it (array[0]) is the getStackTrace()-call, per se. The second (array[1]) is the enclosing method: method2(). And the third one (array[2]) describes the calling method: method1(). :-)