异常处理工具类_基本错误处理工具

异常处理工具类

Introduction

介绍

An error handler is a bit of code which will do pre-defined actions whenever an error occurs. For instance, produce a message to the user or designer describing the nature of the error. For an error handler to be useful, it must provide a minimum of information in its message to the user. Below is a typical example of an error handler I use.

错误处理程序是一些代码,每当发生错误时,它们都会执行预定义的操作。 例如,向用户或设计者生成一条描述错误性质的消息。 为了使错误处理程序有用,它必须在其消息中向用户提供最少的信息。 以下是我使用的错误处理程序的典型示例。

Professional applications need to comprise error handling to trap unexpected errors. By using a consistent error handler, you can make sure that when bangs occur, the user is properly informed and your program exits elegantly. 

专业应用程序需要包含错误处理才能捕获意外错误。 通过使用一致的错误处理程序,可以确保当发生爆炸时,可以正确通知用户并且您的程序可以优雅退出。

Basic error handling just hides the default behavior and exits the program. Advanced error handling can include all sorts of features such as saving information about the cause of the error and the environment at the time, attempts to address the problem, and information for the user on what they need to do next.

基本的错误处理只是隐藏默认行为并退出程序。 高级错误处理可以包括各种功能,例如保存有关当时的错误原因和环境的信息,尝试解决该问题的信息以及有关用户下一步需要做什么的信息。

Basic Error Handling Code

基本错误处理代码

Below is my simple error handling tool, please note that this is just a basic tool, only applies to novice developers, experts may have advanced error handlers and difficult to follow:

以下是我简单的错误处理工具,请注意,这只是一个基本工具,仅适用于新手开发人员,专家们可能拥有高级错误处理程序并且难以遵循:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 2107
MsgBox "The value you entered does not meet the validation rule defined for the field or control", vbOKOnly + vbExclamation, "Error Number 2107"
Response = acDataErrContinue
Case 2113
MsgBox "The value you entered isn't valid for this field", vbOKOnly + vbExclamation, "Error Number 2113"
Response = acDataErrContinue
Case 2169
MsgBox "You can't save this record at this time", vbOKOnly + vbExclamation, "Error Number 2169"
Response = acDataErrContinue
Case 2237
MsgBox "The text you entered isn't an item in the list", vbOKOnly + vbExclamation, "Error Number 2237"
Response = acDataErrContinue
Case 3022
MsgBox "The changes you requested to the table were not successful this may create duplicate", vbOKOnly + vbExclamation, "Error Number 3022"
Response = acDataErrContinue
Case 3200
MsgBox "The record cannot be deleted or changed because table includes related records", vbOKOnly + vbExclamation, "Error Number 3200"
Response = acDataErrContinue
Case 3201
MsgBox "You cannot add or change a record because a related record is required in the table", vbOKOnly + vbExclamation, "Error Number 3201"
Response = acDataErrContinue
Case 3314
MsgBox "Cannot perform cascading operation on table because it is currently in use", vbOKOnly + vbExclamation, "Error Number 3314"
Response = acDataErrContinue
Case 3315
MsgBox "Zero-length string is valid only in a Text or Memo field", vbOKOnly + vbExclamation, "Error Number 3315"
Response = acDataErrContinue
Case 3316
MsgBox "please contact the developer for this kind of error it could be a Corrupt download or incomplete installation ", vbOKOnly + vbExclamation, "Error Number 3316"
Response = acDataErrContinue
Case 2105
MsgBox "You can't go to the specified record you may be at the end of record set", vbOKOnly + vbExclamation, "Error Number 2105"
Response = acDataErrContinue
Case Else
MsgBox "This is an unexpected error occurred" & DataErr & "" & AccessError(DataErr)
Response = acDataErrContinue
End Select
End Sub 

Conclusion

结论

A good error handling tool is very important if developers are to deliver a more user-friendly software.

如果开发人员要交付更加用户友好的软件,那么好的错误处理工具非常重要。

翻译自: https://www.experts-exchange.com/articles/32025/Basic-Error-Handling-Tool.html

异常处理工具类

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值