为什么错误处理很重要? [英] Why is error handling important?

查看:118
本文介绍了为什么错误处理很重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被赋予了为我的团队编写编码指南的任务,直到我的经理要求我写出一个关于为什么错误处理重要的解释。

I was given a task of write the coding guidelines for my team, and it was going great until my manager asked me to write an explanation of Why Error Handling is Important.

我本能地知道,但我如何用言语表达?

I know it instinctively, but how do I express this in words?

我试图先google但是空出来,所以我现在问我的编码向导。

I tried to google it first but came up empty, so I now ask my fellow coding wizards.

推荐答案

IMHO ...大多数程序非常大,非常复杂,人。这些因素的组合几乎总是导致某种软件错误。这不是程序员是恶意的,愚蠢的还是懒惰的...只是在急于满足截止日期的时候,我们经常不会看到用户可以对我们的程序做任何事情,而且一定会发生。

IMHO ... most programs are very large, very complex and written by multiple people. This combination of factors almost always leads to some kind of software bug. It's not that programmers are malicious, stupid or lazy ... it's just that in the rush to meet a deadline we often don't forsee every possible thing that a user can do to our programs and something is bound to happen.

在这方面,错误处理有两个目的。

In this respect error handling serves two purposes.


  • 首先,用户以相对友好的方式知道某些事情出错了,他们应该联系技术支持部门,或者通知技术支持人员。众所周知,收到一个非常令人讨厌的技术说明,说明了Object is not set to reference of a object等等,并收到一个很好的弹出式窗口,说已经有一个问题,请联系帮助台。

  • First, it lets the user know, in a relatively friendly manner, that something has gone wrong and that they should contact the technical support department or that someone from tech support has been notified. As we all know there's a HUGE difference between receiving a rather nasty, tech riddled notice that says something like "Object not set to reference of an object" etc. ... and receiving a nice popup type window that says "There has been an issue. Please contact the helpdesk".

第二,它允许程序员投入一些好处来帮助调试问题。例如...在我的代码中,我通常会写一个自定义的错误处理程序,它接收一些参数,并将一个很好的格式化的邮件发送给可以通过电子邮件发送到帮助台上的信息,这些信息存储在事件日志中,写入日志文件等。错误信息将包含尽可能多的信息,因为我可以在这里填补,以帮助我找出发生了什么,堆栈跟踪,功能参数,数据库调用...你命名。我喜欢详细的错误信息,以帮助我弄清楚实际发生了什么。用户从来没有看到任何一个,他们得到上面漂亮友好的消息,让他们知道有人可以弄清楚发生了什么。

Second it allows the programmer to put in some niceties to aid in the debugging of issues. For instance ... in my code, I typically write a custom error handler that takes in a number of parameters and spits back a nice, formatted message that can either be emailed to the helpdesk, stashed in an event log, written to a log file etc.. The error message will contain as much info as I can cram in there to help me figure out what happened, stack traces, function parameters, database calls ... you name it. I like verbose error messages to help me figure out what actually happened. The user never has to see any of it, they get the nice, friendly message above, letting them know that someone can figure out what's going on.

这篇关于为什么错误处理很重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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