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

前端 未结 7 1031
悲&欢浪女
悲&欢浪女 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:26

    Do not show the exception message / stacktrace directly to the end user. Instead try and use an Exception - Message mapping approach.

    For example:

    • SQLException - Sorry, a database error occurred. Please try again later
    • RuntimeException / Exception - Sorry an error occurred. Please try again later

    In fact, you can make it as generic as possible. Perhaps you could use a custom error code mapping. For instance, E0001 for SQLException, E0000 for Exception and so on and display this to the end user. This will be helpful when they eventually contact the customer service with the error code.

提交回复
热议问题