|
-
Apr 2nd, 2002, 02:22 PM
#1
Thread Starter
Lively Member
error
Hi!!
i would like to how work the OnError GoTo .....
In my form i have to do a lot of thing in my button insert and if something happening strange when i pressed the button insert i want to catch the error.
How dont know how to do.
how do we do to know which number of error!!!
thank lot
-
Apr 2nd, 2002, 02:24 PM
#2
VB Code:
Private Sub Command1_Click()
On Error Goto ErrRtn
'code to do your thing
Exit Sub
ErrRtn:
Msgbox Err & " " & Error
End Sub
-
Apr 2nd, 2002, 04:27 PM
#3
Be careful with the error handlers. It is sometimes best to have
one for each section of code, sometimes one handler for the
entire program.
When you have declared "on error goto dumb" that stays in force
until the next on error statement. Thus, 25 system calls and
1000 VB lines of code later, you'll endup at dumb if you create an
error.
BTW, on error goto 0 clears the last error goto statement.
Good Luck
-
Apr 2nd, 2002, 04:51 PM
#4
PowerPoster
I like to use functions and have them return an error code and then raise the error from the originating procedure. I don't always do that if I definitely want to log the error where the error occured. The plus side to this is that I don't have to make sure only one error message is raised if the call is coming back up through several procedures. The downside is that the error isn't reported where it actually occured.
I also log errors in a central handler unless they are validation errors (bad user input).
VB Code:
Sub A ()
dim ireturn as long
on error goto errhandler
ireturn = savefile
if ireturn <> 0 then err.raise ireturn
exit sub
errHandler:
logerror error, err
End sub
Function SaveFile() as long
dim iReturn as long
on error goto errhandler
iReturn = Validate
if iReturn <> 0 then err.raise ireturn
iReturn = GetFilename
if iReturn <> 0 then exit function
iReturn = WriteFile
if iReturn <> 0 then exit function
exit function
errHandler:
logerror error, err
end Function
function Validate
on error goto errhandler
' do validate stuff
exit function
errHandler:
msgbox "You did dumb data input stuff."
end function
function GetFilename
on error goto errhandler
' do stuff
exit function
errHandler:
logerror
end function
and so on
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|