Java: what information in error stack trace do we typically not wish to show users?

前端 未结 7 1028
悲&欢浪女
悲&欢浪女 2020-12-11 02:47

I\'m new to java and I\'m not that familiar with the formatting rules used by an error stack trace when it is thrown and subsequently displayed to an end-user of my web appl

7条回答
  •  执念已碎
    2020-12-11 03:12

    As others have said, you should not report the stack-trace to users. Several others have suggested you display the getMessage() text. I recommend not doing that. As I've said before:

    • The message was created when the exception was thrown. It therefore at best can provide only very low level information, which can be inappropriate for reporting to a user.
    • Philosophically, using the message seems to me against the whole point of exceptions, which is to separate the detection and initiation of error handling (the throw part) from completion of handling and reporting (the catch part). Using the message means the message must be good for reporting, which moves responsibility for reporting to the location that should be responsible for only detection and initiation. That is, I'd argue that the getMessage() part of the design of Throwable was a mistake.
    • The message is not localised. Despite its name, getLocalizedMessage() is not much good because you might not know what locale you want to use until you catch the exception (is the report to go to a system log read by your English system administrators, or is it to pop up in a window for the French user of the GUI?).

提交回复
热议问题