[URGENT] Declaring an error handler like this... simple, but can someone help?
I want to declare an error handler like this if possible...
ErrorHandler:
Case err.number whatever
If err.description "whateverdescription" Then
MsgBox "do whateverdescription needs"
Else: MsgBox "a different error message"
Case err.number whateverelse
Msgbox "message for whatever else"
Case err.number yetanother
Msgbox "message for yetanother"
Case else
Msgbox "error handler to catch all other others not accounted for"
Can someone help me write it?
I've been trying it, but i keep either getting errors (like End Select declared in wrong place), or jumping errors and always going to the last one for some reason...
Here i have shown a example where for invalid data a error
message will be poped
Option Explicit
Dim i As Integer
Dim k As Integer
Private Sub cmderrorhandler()
On Error GoTo Errorhandler
i = Val(txtnumber.Text)
k = 50 / Val(txtnumber.Text)
Errorhandler:
Select Case Err.Number
Case 6
If Err.Description = "Overflow" Then
MsgBox "Enter a number less than 32567"
Else
MsgBox "something"
End If
Case 11
If Err.Description = "Division by zero" Then
MsgBox "Enter a number other than zero"
Else
MsgBox "something"
End If
Case Else
MsgBox "Cannot find out the error"
End Select
End Sub
Re: [URGENT] Declaring an error handler like this... simple, but can someone help?
Originally posted by VBKid04 I want to declare an error handler like this if possible...
ErrorHandler:
Case err.number whatever
If err.description "whateverdescription" Then
MsgBox "do whateverdescription needs"
Else: MsgBox "a different error message"
Case err.number whateverelse
Msgbox "message for whatever else"
Case err.number yetanother
Msgbox "message for yetanother"
Case else
Msgbox "error handler to catch all other others not accounted for"
Can someone help me write it?
I've been trying it, but i keep either getting errors (like End Select declared in wrong place), or jumping errors and always going to the last one for some reason...
If anyone can please lend some help, please do.
Many thanks.
Why are you asking the same question in multiple places?
Here is some greate error handler code.
Not only can you display all your error messages in a custom screen, but it also records the entire route that the error was transmitted through and allows the user to email a helpdesk.
VB Code:
Private Sub Command1_Click
On Error Goto ErrHandler
Call Woof
Exit Sub
ErrHandler:
MsgBox Err.Description
End Sub
Private Sub Woof()
Call Growl
End Sub
Private Sub Growl()
MsgBox 1/0 'force error
End Sub
With the above you get an error when you click the command button. As a developer this isn't much use as with a very large app this error could have been generated by 1 of 200 subs/functions.
The error handler zipped up here would display the following error:
Code:
ORIGINATED:
cmdCommand1_Click
HISTORY:
Woof
Growl
This means it's easy to pin point exactly which function caused the error.
Hope this helps.