Forum Moderators: phranque
On error goto 0 turns off error trapping.
On error goto myerrline, is used, for example to bring up an error box to explain what the error was to and end user or to fix the error. Then you want to ‘resume myresumeline’ to try the code that caused the error again.
"on error goto 0" is the default MS handler. Very nasty scarry messages.
"on error goto [put your label here]" will just execution to an error handler in your current subroutine with that label.
Remember right before the label you do an "Exit Funtion" or "Exit Sub" to make sure normal execution will not get to the handler.
daisho
"on error goto 0" is the default MS handler. Very nasty scarry messages.
That's because it turns error trapping off. Refer to the help file. It shows examples. Also see the MS knowledge base.
http: //support.microsoft.com/default.aspx?scid=kb;en-us;32272
These commands have actually been around since pre 1983 when using interpreted MSBASIC and PCBASIC with DOS 2.x
I'm here would like to know about the ASP error handling ->
on error resume next statment.
1.) In order to catch an error which might occur anywhere in an asp page, i out the on error resume next statement on top of the asp page and put the message: if err.number <> 0 then response.write "error has occured" at the bottom of the asp page. Does it correct?
2.) just assume that an error has occurred, the ASP engine will skip that error and continue executed the next line of code right? I found it when the I failed to register, a successful message still displayed.
Pls help!
come back again,
I'm really confused with the ASP error handling statement on error resume next.
1.) I don't know how many on error statement should I put in one page for detecting any error occur during runtime. Normally, I use on top of every page of my page, and raise the error description at bottom of the page.
2.) I'm really confused on the On Error Resume Next used in Function and Procedure. Different error will be returning if you try to off on on the on error resume next statement in the functions
For instance : I have two three functions :
Function DbConnectionOpen(ByVal DataPath)
Dim objDC
on error resume next
'Create and establish data connection
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.ConnectionTimeout = 15
objDC.CommandTimeout = 30
'Use this line to use Access
objDC.Open "DBQ=" & DataPath & ";Driver={Microsoft Access Driver
(*. mdb)};DriverId=25;MaxBufferSize=8192;Threads=20;ui
d=;pwd=1234"
If err.number <> ) Then
Response.Write err.Description
End If
Set DbConnectionOpen = objDC
End Function
Function RsOpen(ByVal strSQL, ByVal objDC)
Dim objRS
on error resume next
'talk to the database using ADODB.Recordset
Set objRS = Server.CreateObject("ADODB.Recordset")
with objRS
.ActiveConnection = objDC
.CursorLocation = adUseClient
.CursorType=adOpenDynamic
.LockType=adLockOptimistic
end with
objRS.Open strSQL, objDC
Set RsOpen = objRS
If err.number <> ) Then
Response.Write err.Description
End If
End Function
Sub callRecord(datacon, tablename)
' on error resume next (on and off for testing)
Set objDC = DbConnectionOpen(DataPath)
sSQL="SELECT * FROM " & tablename
Set objRS = RsOpen(sSQL, objDC)
objRS.AddNew
........
objRS.Update
objRS.Close
Set objRS = Nothing
objDC.Close
Set objDC = Nothing
If err.number <> ) Then
Response.Write err.Description
End If
End Sub
CALL FROM ASP PAGE:
On error resume next is put on top of my page
.
.
.
.
DataPath = Server.MapPath("/data/myData.mdb")
callRecord DataPath, tablename
.
.
.
.
If err.number <> 0 Then
err.Description
End If
When I tried to put the on error resume next statement in the Connection function, this error is displayed:
Error from function: [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x870 Thread 0x8cc DBC 0x13c9e9c Jet'.
Error from Asp Page:
The connection cannot be used to perform this operation. It is either closed or invalid in this context.
If I tried to off the on error resume next statement on the connection function, this error will be displayed ASP Page which called the function:
[Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x870 Thread 0x8cc DBC 0x13c9e9c Jet'.
When I tried to On the on error resume next in the callRecord function, things happen differently as well with different error description generated.
3.) May I know how do I put the on error resume next statement correctly in functions and procedures?
Please help?
Last edited by charon on 04-29-2003 at 01:41 AM
Do a google search for VB2TheMax or VBNet to better understand what is happening and to see examples of error trapping usage.
on error resume next statement
You should only use this if you are sure that continuing the program will not cause additional errors.
Your problem is not with the on error statement. From what you described, it is working as designed.