Forum Moderators: phranque

Message Too Old, No Replies

on error resume next and on error goto 0

         

charonlee

12:37 pm on Apr 28, 2003 (gmt 0)

10+ Year Member



hi, what are the different between these two statement?

macrost

4:05 pm on Apr 28, 2003 (gmt 0)

10+ Year Member



On error resume next
is a basic error trapping statement in asp if I remember right. I would never use a goto statement! That can be very detremental to any code that is written.
Mac

jim_w

4:19 pm on Apr 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



on error resume next will run the next line(s) of code in the program whether the program encountered an error or not.

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.

daisho

4:36 pm on Apr 28, 2003 (gmt 0)

10+ Year Member



"on error resume next" will just continue with the next statement when an error is raised.

"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

jim_w

4:53 pm on Apr 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"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

daisho

5:04 pm on Apr 28, 2003 (gmt 0)

10+ Year Member



Yup I know that. User error trapping is turned off and theirfore goes to the default nasty MS internal handler. I've been playing with basic since the days of gwbasic. Though I don't really want people to know that ;)

jim_w

5:14 pm on Apr 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, we'll both pretend like nothing was said!

daisho

5:29 pm on Apr 28, 2003 (gmt 0)

10+ Year Member



Sounds good. It's a deal :)

charonlee

9:42 am on Apr 29, 2003 (gmt 0)

10+ Year Member



on error resume next statement
hi,

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

jim_w

1:17 pm on Apr 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your not trapping, or isolating the first error and correcting it, therefore, more errors occur as the program continues.

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.

charonlee

12:08 pm on May 8, 2003 (gmt 0)

10+ Year Member



Just curious to know:
1.) Since by putting the On Error Resume Next in The ASP PAGE which call the function already be able to catch the error, why we still need to put it inside the function as it be able to handler the error inside the function as well.