Stack Tracing
in Java |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
StackTraceElement
:
StackFrameElement
objects are organized into a
last-in, first-out (LIFO) "collection" (called a stack)StackFrameElement
object (except,
perhaps, the top-most) represents
a method invocationStackFrameElement
object can
represent an execution point (e.g., the point at which
a Throwable
was created)main()
), the program terminates
and a message is printedStackFrameElement
objectsgetStackTrace()
method in the
Throwable
class will return the stack trace
(i.e., the LIFO StackTraceElement[]
) that was
created when the Throwable
was created
getStackTrace()
method belonging to
a Thread
object returns its current stack trace
and the current Thread
(loosely, the current
sequence of instructions) can be obtained
using the static currentThread()
method in the
Thread
classgetClassName()
getFileName()
getLineNumber()
getMethodName()
The Stack Trace:
OverdraftAccount.amountAvailable(OverdraftAccount.java:20) Account.withdraw(Account.java:59) Driver.main(Driver.java:36)