什么时候适合使用错误代码? [英] When is it appropriate to use error codes?

查看:167
本文介绍了什么时候适合使用错误代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在支持异常对象(Java,C#)的语言中,何时使用错误代码<一>?是否在典型的企业应用程序中使用错误代码?

In languages that support exception objects (Java, C#), when is it appropriate to use error codes? Is the use of error codes ever appropriate in typical enterprise applications?

许多知名的软件系统采用错误代码(和相应的错误代码参考)。一些示例包括操作系统(Windows),数据库(Oracle,DB2)和中间件产品(WebLogic,WebSphere)。错误代码提供什么好处?使用错误代码有什么缺点?

Many well-known software systems employ error codes (and a corresponding error code reference). Some examples include operating systems (Windows), databases (Oracle, DB2), and middle-ware products (WebLogic, WebSphere). What benefits do error codes provide? What are the disadvantages to using error codes?

推荐答案

WITHIN 一个程序应该总是使用异常的错误代码。但是,异常无法传播超出程序。任何时候,错误必须离开程序,留下错误信息或错误代码。

WITHIN a program one should always use exceptions instead of error codes. However, exceptions can't propagate beyond a program. Any time the error must leave the program you are left with error messages or error codes.

对于简单的东西,永远是人为的错误消息没有代码是正常的。您可以说找不到文件,而不给出错误代码。但是,如果另一端可能是另一台计算机,那么你应该给出错误代码。当您将其更改为File< x> not found时,您不想破坏其他系统。

For simple things that will always be human-operated error messages without codes are fine. You can say "File not found" without giving it an error code. However, if it might be another computer on the other end then you should give error codes in addition. You don't want to break the other system when you change it to "File <x> not found".

这篇关于什么时候适合使用错误代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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