What is the use of printStackTrace() method in Java?

后端 未结 10 1840
不知归路
不知归路 2020-12-02 06:35

I am going through a socket program. In it, printStackTrace is called on the IOException object in the catch block.
What does printStackT

10条回答
  •  长情又很酷
    2020-12-02 07:14

    It's a method on Exception instances that prints the stack trace of the instance to System.err.

    It's a very simple, but very useful tool for diagnosing an exceptions. It tells you what happened and where in the code this happened.

    Here's an example of how it might be used in practice:

    try {
        // ...
    } catch (SomeException e) { 
        e.printStackTrace();
    }
    

提交回复
热议问题