-1

I encountered this method when I'm reading a java book. I've looked for its meaning in java doc but it's difficult to understand. Can you tell me its meaning in easy to understand way?

Beau Grantham
  • 3,435
  • 5
  • 33
  • 43
helloJava
  • 21
  • 2

2 Answers2

1

Simple Phrase

Print stack trace tells you two things:

  • Where you are (in the code)
  • How you got there

Example

If main() calls foo(), foo() calls bar(), and bar() calls printStackTrace(), you will get a structure that looks like main() => foo() => bar().

Rainbolt
  • 3,542
  • 1
  • 20
  • 44
0

It prints the stack trace (most probably of an exception) to the console.

The stack trace specifies where in the code (hierarchically) you have been when the exception has been thrown, e.g.:

in method Worker.Run in Worker.java
called from method Main in Program.java
...

The format is different, but you should get the notion.

This helps you to learn which execution stack caused the exception (hence the name stack trace).

D.R.
  • 20,268
  • 21
  • 102
  • 205