Handle Error.

  • Thread starter Thread starter =?gb2312?B?Q2FjdHVzIFvPycjLx/Jd?=
  • Start date Start date
?

=?gb2312?B?Q2FjdHVzIFvPycjLx/Jd?=

A procedure often Number Overflow.
So I put this handler in procedure.


Private Sub Hint()

On Error GoTo Overflow
....... ' Some codes.
Exit Sub

Overflow:
If (Err = 6) Then
......' Handling error.
End If

End Sub


but if other Error happen.
it could be a unhandle error.
because I not handing all err number.
 
Hi

I suggest a Select Case structure on err number, like this:

Sub test()
Dim i As Long

On Error GoTo ErrHandler

i = 23232323232323# ^ 2
MsgBox "i=" & i

i = 23 / 0
MsgBox "i=" & i

Exit Sub

ErrHandler:
Select Case Err.Number
Case 6
MsgBox "Overflow"
i = 500
Resume Next
Case 11
MsgBox "Div 0"
i = 0
Resume Next
Case Else
MsgBox Error, Err.Number
End Select
End Sub

You may find a list of errors useful when you work on this. Run this on a
blank worksheet:

Sub ErrorList()
Dim L As Long
Dim R As Long
On Error Resume Next
For L = 1 To 1000
Err.Raise L
If Error <> "Application-defined or object-defined error" Then
R = R + 1
Cells(R, 1).Value = Err.Number
Cells(R, 2).Value = Error
End If
Err.Clear
Next
End Sub


HTH. Best wishes Harald
 
Harald


Well, that Err Number List is great.
Can I using this way?
Throws Err to default handler.


Overflow:
If (Err = 6) Then
.....' Handling error.
Else
Err.Raise Err
End If
 
Back
Top