Home > ASP Development > Debugging Problems

Debugging Problems



I'm trying to create an application and capture my bugs using the old "on error resume next" statement. However, when it hits a bug it just stops dead.. Any ideas, before I rip my hair out?



Below is a test script that produces the result specified above. The script should send an email to me to tell me of the error, but instead it just quits the getFromDatabase sub and continues the main part of the code!






Code:



<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
sub openDb()
if varType(connTemp)=0 or varType(connTemp)=1 then
' create the connection
set connTemp = server.createObject("adodb.connection")
connTemp.Open MM_RockManager_STRING
end if
end sub

sub getFromDatabase(mySQL, rsTemp, scriptName)
'response.write scriptName & " - " & mySQL & "****"
call openDb()
set rsTemp = server.createObject("adodb.recordset")
' set locktype
rsTemp.lockType = adLockReadOnly
' set the cursor
rsTemp.cursorType = adOpenForwardOnly
'response.write mySQL
rsTemp.open mySQL, connTemp

'Do error checking
If err.number <> 0 then
tmpMessage = "ERROR FOUND<br /><br />" &_
"getFromDatabase: " & scriptName & " ... Band ID: " & tmpBandID & "<br /><br />"&_
" Source: " & err.source &_
" Number: " & err.number &_
"Description: " & err.description & "<br /><br />"&_
"Now: " & now()
sendEmail "[name]", "[email]", "Bug Report!", tmpMessage
err.clear
end if
end sub
%>
<%
on error resume next

mySql="SELECT * FROM tbl_Bandsfgh WHERE bandName = 32;"
call getFromDatabase (mySql, rsTemp, "LoginMember")

response.write("test text")

%>



    
Guest


rather than having the on error code in a sub function try putting the on the page instead and retry it.

Was this answer helpful ? Yes No   
Guest


I've tried the on error in different places, doesn't make a difference

Was this answer helpful ? Yes No   
Guest


well here is an example of code for a on error page:




Code:



<%@ LANGUAGE="VBScript" %>
<%
' ### Turn on page buffering ###
Response.Buffer = True

' ### Turn On Error Handling ###
On Error Resume Next

' ### Your ASP Page code goes HERE! ###

' ### Error Handler ###
If Err.Number <> 0 Then
' ### Clear response buffer ###
Response.Clear

' ### Display Error Message to user ###
%>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY BGCOLOR="#C0C0C0">
<FONT FACE="ARIAL">An error occurred in the execution of this ASP page<BR>
Please report the following information to the support desk<P>
<B>Page Error Object</B><BR>
Error Number <%= Err.Number %><BR>
Error Description <%= Err.Description %><BR>
Source <%= Err.Source %><BR>
LineNumber <%= Err.Line %><BR>
</FONT>
</BODY>
</HTML>
<%End If%>



Was this answer helpful ? Yes No   
Guest


I'm not sure, but maybe when there is an error, the

compiler steps out of all sub routines. try having this

block of code outside the function:


Code:



'Do error checking
If err.number <> 0 then
tmpMessage = "ERROR FOUND<br /><br />" &_
"getFromDatabase: " & scriptName & " ... Band ID: " & tmpBandID & "<br /><br />"&_
" Source: " & err.source &_
" Number: " & err.number &_
"Description: " & err.description & "<br /><br />"&_
"Now: " & now()
sendEmail "[name]", "[email]", "Bug Report!", tmpMessage
err.clear
end if




also, maybe the sendEmail itself has errors....

Was this answer helpful ? Yes No   
Guest


Yeha - it works outside of the function but i'd have to repeat the code soooooooo many times!

Was this answer helpful ? Yes No   
Guest


From the ms documentation

Quote:

An On Error Resume Next statement becomes inactive when another procedure is called, so you should execute an On Error Resume Next statement in each called routine if you want inline error handling within that routine. When a procedure is exited, the error-handling capability reverts to whatever error-handling was in place before entering the exited procedure.

Was this answer helpful ? Yes No   
Guest


If that was the case then surely when the error occured in the procedure. it'd "crash" and report the error to screen - Like a usual ASP error, instead of just exiting the sub.



Anyway.. I'll try it when I get home.. Thanx for the reply

Was this answer helpful ? Yes No   
Guest


You can use On Error GoTo 0 to disable On Error Resume Next, this is often helpful if you are trying to find out where On Error Resume Next is working. In a production app, the user should NEVER see the error messages, these should either be logged locally or e-mailed or both even.

Was this answer helpful ? Yes No   
Guest


Big thanx to Doug G!



I put the "on error resume next" into the sub procedure and everything works fine!

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved