错误处理:是否显示错误消息?

发布于 2024-09-11 01:58:33 字数 173 浏览 6 评论 0原文

一般来说,在软件设计中,当数据库或文件等资源出现问题或错误时,首选以下哪个选项?

  1. 显示错误消息
  2. 不要显示错误消息,并且表现得好像资源为空(例如,不填充 GUI 组件)]

例如,如果用户在抱怨后看到一个空的 DataGrid,或者应该出现错误信息?哪个更好?

Generally, in software design, which of the options below is preferred when there is a problem or error with a resource such as a database or file?

  1. Show an error message
  2. Do not show an error message and act as though the resource was empty (eg. do not populate a GUI component)]

For example, should the user see an empty DataGrid following which they complain, or should there be an error message? Which is better?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

短暂陪伴 2024-09-18 01:58:33

我不认为这是一个非此即彼的问题。另外,我们需要考虑系统的所有“用户”。

首先考虑用户界面。让我们考虑一个人为的一般情况:您通过调用一个服务来填充 UI,该服务又使用几个数据库(例如“当前数据”和“历史数据”)数据库。

至少存在以下可能性:

  • 一切正常,检索数据
  • 一切正常,但碰巧此特定查询没有数据
  • 无法到达服务
  • 服务已调用,但一个数据库已关闭
  • 服务已调用,但两个数据库均已关闭然后

还要考虑应用程序的语义。如果无法检索所有数据,您的应用程序能否以“降级”模式继续运行?例如,我们无法查询历史记录,但这并不妨碍我们创建新项目。

现在还要考虑这里的角色。有使用 UI 的人员,也有需要了解和解决问题的支持和维护人员。

我的一般规则:

  1. 第一次失败数据捕获:无论哪个组件首先检测到错误,都应该详细记录它。所以,服务启动,数据库关闭,服务应该记录问题。服务关闭,UI 应记录问题。该日志应该是针对支持角色的技术记录。
  2. UI 应该是宽容的:如果可能的话,可以在降级模式下运行。因此,如果服务已关闭,但(例如)可以进行本地工作,则可以显示一个空屏幕并继续。但是...
  3. 始终指出问题:“此查询没有数据”和“数据库不可用”情况都可能导致空白屏幕。用户需要知道显示器的状态,是显示完整信息、部分信息(例如,因为一个数据库已关闭)还是没有可用信息(例如,服务或两个数据库都已关闭)。因此,在屏幕上的某个位置有一个“状态”字段。发出诸如

历史数据当前不可用

检索时出现问题
信息,如果这些仍然存在,请
联系支持...

I don't see this as an either/or. Also, we need to consider all "users" of the system.

First consider the UI. Let's consider a contrived general case: you are populating a UI by calling a service which in turn uses a couple of of databases (for example a "current data" and an "historic data") database.

There are at least these possibilities:

  • It all works, data is retrieved
  • It all works but as it happens there's no data for this particular query
  • Can't reach the service
  • Service is invoked, but one database is down
  • Service is invoked, but both databases are down

Then also consider your application's semantics. Can your applciation procede in a "degraded" mode if all the data cannot be retrieved? For example, we can't query the history but that doesn't stop us creating a new item.,

Now also consider the roles here. There's the person using the UI, there's also support and maintenance people who need to know about and fix problems.

My general rules:

  1. First Failure Data capture: Whichever component first detects an error should log it in some detail. So, service up, database down the service should log the problem. Service down, the UI should log the problem. This log should be a technical record targeting the support roles.
  2. UIs should be tolerant: if at all possible run in a degraded mode. So if the service is down but (for example) local working is possible put up an empty screen and continue. BUT ...
  3. Always indicate a problem: The "no data for this query" and "databases unavailable" cases may both result in an empty screen. The user needs to know the status of the display, is it showing complete information, partial information (eg. because one DB is down) or is no information available (eg. service or both dbs down). So have a "Status" field somewhere on the screen. Giving messages such as

Historica Data not currently available

or

There are problems retrieveing
information, if these persist please
contact support ...

慵挽 2024-09-18 01:58:33

每个选项都有一些陷阱

显示错误消息

当您的应用程序处于测试阶段或公共测试时,这特别有用。此外,当客户遇到错误时,他或她可以复制详细信息并发送给您。

然而,有时此错误消息会变得非常难看(调用堆栈等 - 还记得 ASP.NET 吗?),并且它变得如此之大,以至于客户端很难复制详细信息。

不要显示错误消息并表现得好像什么都没发生一样 =)

当您不希望错误消息影响您的软件 UI 设计时,这非常有用。但请注意,当客户端无法区分实际错误或 GUI 上实际上没有任何错误时,这会变得很困难并且更容易出错。错误仍然存​​在,没有任何内容得到修复。

我的立场

两全其美。事实上,大多数现代应用程序都有一个非常好的错误处理过程。我以 Mozilla Firefox 3 为例。

  1. 发生致命错误,Firefox 崩溃
  2. 错误被捕获并以错误报告的形式存储到文件中
  3. 弹出错误报告应用程序,向用户道歉
  4. 询问用户是否要发送向软件开发团队报告错误
  5. 然后询问用户是否要重新启动应用程序

或者错误是否是警告或较轻的严重性:
显示一个简单的错误代码并告诉用户该操作存在错误。类似于:“RequestSalary() 第 2 行出现错误 123”

There are some pitfalls to each of the options

Showing error message

This is specially helpful when your application is in testing stage or public testing. Also when clients meets an error, he or she can copy down the details and forward to you.

However sometimes this error message gets very ugly (call stacks and so on - remember ASP.NET?) and it becomes so large that it becomes difficult for clients to copy down the details.

Do not show error message and act as though nothing happened =)

This is useful when you don't want error messages to cog up your software UI design. But be reminded that it becomes difficult and further error prone when clients can't differentiate between an actual error, or really nothing on the GUI. The error stays there and nothing gets fixed.

My stand

Get the best of both worlds. In fact most modern applications how have a very good error handling process. I'll take the example of Mozilla Firefox 3.

  1. A deadly error occurred and Firefox crashes
  2. Error is captured and stored into a file as a form of error report
  3. Error Reporting Application pops up apologizing to the user
  4. Ask the user if the user want to send the error report to the software dev team
  5. Then ask the user if want to restart the application

Or if the error is a warning or of lesser severity:
Show a simple error code and tell the user that there's the error with that action. Something like: "Error 123 at RequestSalary() Line 2"

满天都是小星星 2024-09-18 01:58:33

我通常使用的做法是:

  1. 如果错误不是由于用户错误而发生的,那么你应该尝试安静地处理错误。
  2. 如果由于某些外部问题(例如没有互联网连接)而发生错误,那么您应该提醒用户。

The practice I usualy use is:

  1. If the error didn't happen due to user error, then you should try to handle the error quietly.
  2. If the error occurred because of some external problem (such as no internet connection) then you should alert the user.
挽你眉间 2024-09-18 01:58:33

在我看来,您应该显示一条消息(尽管是一条用户友好的消息,而不是类似“java.io.IOException:连接超时”之类的消息。)您可以有一个消息框,告诉用户在获取数据时发生错误并提供有用的提示比如:过一段时间再尝试,检查网线等。
还允许用户向您报告该错误(应用程序中内置错误报告),这将向您发送实际的错误和堆栈跟踪。

IMO you should show a message (albeit a user friendly one and not something like "java.io.IOException: Connection timed out".) You could have a message box telling the user that an error occured while getting the data and provide helpful tips like: Trying after some time, check network cable, etc.
Also allow user to report that error to you (error reporting build into the app) that will send you the actual error and stack trace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文