Click to See Complete Forum and Search --> : what does this do: on error resume next


sneakyimp
08-15-2004, 12:59 AM
ok i know it says "on an error go to the next statement" but my script is behaving all wacko. it would seem that the entire rest of the subroutine is skipped. i know the database execute is causing an error here...i don't know why the script continues running but only OUTSIDE this subroutine:


Sub SaveEntry
'on error resume next

sql="INSERT INTO MailingList (Name,Email,DateAdded,Age,ZipCode,Country,Gender,HeardAbout) VALUES "
sql=sql & "('" & gName & "','" & gEmail & "',#" & Now() & "#,'" & gAge & "','" & gZipCode & "','" & gCountry & "','" & gGender & "','" & gHeardAbout & "')"

Response.Write "we're saving...sql:" & sql & "<BR>"


set conn=Server.CreateObject("ADODB.Connection")
conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("data/lustra.mdb")
conn.Open

Result = conn.Execute(sql,numRecordsAffected)
Response.Write "numRecordsAffected:" + numRecordsAffected
Response.Write "error:" + Err.Number
if Err <> 0 then
ErrMsg = "An error occurred: " & err.description
Elseif IsNull(numRecordsAffected) = "" then
ErrMsg = "FAILED. Your information was not saved. no records were affected."
%>
Your name has been entered!
</body></html>

<%
Response.End()
end if

conn.Close
End Sub

buntine
08-15-2004, 04:37 AM
It will skip the rest of the sub-routine if an error occurs. It is very similar to the try-catch statements in Java.

It means if an error occurs during this script, dont send an error report to the client, just move onto the next routine.

Regards.

sneakyimp
08-15-2004, 05:04 AM
thanks, buntine...

i'm in touch with the current developer about this nonsense. what a shame! the subroutine that calls the database access can't trap the error. i miss PHP and MYSQL!

buntine
08-15-2004, 06:34 AM
Yes, ASP is a redundant technology. We have all moved on up to .NET, which is now leading the industry.