用户可理解的异常错误消息 [英] User understandable Exception Error Messages

查看:87
本文介绍了用户可理解的异常错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以更易理解的方式显示.net异常。

How to show .net exception in more understandable way.

推荐答案

唯一的方法是捕获异常并将其翻译为您的语言...

但是,为什么最终用户应该看到异常?

在我们的应用程序中,当发生意外错误(例外)时,我们将其记录到具有唯一编号的DB中,并且只通知最终用户发生了意外错误并且只丢弃了日志中的数字,并提供了通过电子邮件向我们发送错误的选项...稍后我们检查日志中的确切错误并根据需要进行处理。 ..
The only way is to catch the exception and 'translate' it to your language...
However, why end user ever should see an exception?
In our application, when unexpected error occurs (an exception) we log it into a DB with a unique number, and only inform the end user that an unexpected error has occurred and give away only the number in the log, with an option to send us the error by email...Later we check the log for the exact error and handle it as needed...


这取决于许多因素:

1)您的用户是谁。如果他们是开发人员,那么正确的错误消息可能有点帮助 - 连接字符串错误,INSERT中的语法错误或类似信息告诉他们这可能是你的错,而不是他们的错,他们可能想要尝试稍有不同。如果它们是非技术性的,那么任何复杂的事情都是错误的 - 彼得在解决方案1中建议的方法是最好的。在两者之间?这是一种平衡行为。

2)这取决于错误!如果在转换用户输入时出错,那么您需要告诉他们 - 但您应该自己检查并报告一条非常具体的消息请在'出生日期'框中输入有效日期而不是让它首先得到一个例外。如果是因为与DB的连接已经死亡并且您无法访问数据,则单独捕获DBException并报告与数据库通信存在问题,请稍后再试是个好主意。

3)这取决于错误会导致什么。如果这是一个微不足道的问题,只会影响用户最后输入的字符,那么消息就不那么重要了,系统给出的一般错误消息就足够了。如果这意味着他们即将失去一小时工作......那么你最好详细解释一下! :笑:



一般来说,如果您捕获特定的例外情况,比如大多数用户的例外情况,提供更好的错误很困难。 DBException等不是总是只使用catch-all Exception对象。当然,在所有情况下都没有一条更好的错误消息!
It depends on a number of factors:
1) Who your users are. If they are developers, then the "proper" error message is probably a little helpful - a connection string error, a "syntax error in INSERT", or similar tells them that it's probably your fault, rather than thiers, and they might want to try slightly differently. If they are "non-technical" then anything complicated is a mistake - and the approach Peter suggests in Solution 1 is best. In between? That's a balancing act.
2) It depends on the error! If it's an error in converting user input, then that's what you need to tell them - but you should be checking it yourself and reporting a very specific message "Please enter a valid date in the 'Date of Birth' box" rather than letting it get to an exception in the first place. If it's because the connection to the DB has died and you can't access data, then trapping DBException separately and reporting that "there is a problem communicating with the database, please try again later" is a good idea.
3) It depends what will happen as a result of the error. If it's a trivial problem that will impact just the character the user last typed, then the message isn't that important and a generic error message as given by the system is probably enough. If it means they are about to lose an hours work...then you better explain that in good detail! :laugh:

Generally, it's difficult to provide a "better" error than the one that comes with the exception for most users, provided that you trap specific exceptions such as DBException and such like instead of always using just the catch-all Exception object. Certainly there isn;t a single "better error" message you can use in all cases!


这篇关于用户可理解的异常错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆