Avoid printStackTrace(); use a logger call instead

前端 未结 7 1220
我寻月下人不归
我寻月下人不归 2020-12-07 11:05

In my application, I am running my code through PMD.It shows me this message:

  • Avoid printStackTrace(); use a logger call instead.
7条回答
  •  囚心锁ツ
    2020-12-07 11:55

    Let's talk in from company concept. Log gives you flexible levels (see Difference between logger.info and logger.debug). Different people want to see different levels, like QAs, developers, business people. But e.printStackTrace() will print out everything. Also, like if this method will be restful called, this same error may print several times. Then the Devops or Tech-Ops people in your company may be crazy because they will receive the same error reminders. I think a better replacement could be log.error("errors happend in XXX", e) This will also print out whole information which is easy reading than e.printStackTrace()

提交回复
热议问题