Central Error Handler
The following code provides the means of adding a Centralized Error Handler to an application. I keep the Public Function in a Module named ErrorHandling to keep things simple.
AI
AI 摘要: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
源代码
Option Explicit
'The Following Code gets added to each Sub in which you
'Would like to trap errors in.
ErrHandler:
Dim iErrorAction As Long
iErrorAction = ErrorHandler(Err)
Select Case iErrorAction
Case 1
Resume
Case 2
Resume Next
Case 3
'Case 3 is for Resume to a Line, otherwise left blank
Case 4
Exit Sub
Case 5
End
End Select
'The code below remains in a Module where it can be expanded in one central location
Public Function ErrorHandler(iErrNum) As Long
Dim iAction As Long
Select Case iErrNum
Case -2147467259
MsgBox "A database data entry violation has occurred. " & "Error Number = " & iErrNum
iAction = 5
Case 5
'Invalid Procedure Call
MsgBox Error(iErrNum) & " Contact Help Desk."
iAction = 2
Case 7
'Out of memory
MsgBox "Out of Memory. Close all unnecessary applications."
iAction = 1
Case 11
'Divide by 0
MsgBox "Zero is not a valid value."
iAction = 1
Case 48, 49, 51
'Error in loading DLL
MsgBox iErrNum & " Contact Help Desk"
iAction = 5
Case 57
'Device I/O error
MsgBox "Insert a disk into Drive A."
iAction = 1
Case 68
'Device Unavailable
MsgBox "Device is unavailable(the device may not exist or it is currently unavailable)."
iAction = 4
Case 482, 483
'General Printer Error
MsgBox "A general printer error has occurred. Your printer may be offline."
iAction = 4
Case Else
MsgBox "Unrecoverable Error. Exiting Application. " & "Error Number = " & iErrNum
iAction = 5
End Select
ErrorHandler = iAction
End Function
原始评论 (3)
从 Wayback Machine 恢复