Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

More info on error messages needed

Status
Not open for further replies.

fiorine

Programmer
Jun 25, 2001
4
0
0
US
Before I added 'on error resume next' and put a pretty message up for the user, I got the standard asp error messages spit out at me...and they had the linenumber and filename of the location in the file that the compiler blew up on. I am trying to write the error messages to a table and emailing it to the support email address, but the error object does have any functionality to capture the line number and file name of the place the error occured, is there an easy way to do this without hardcoding the values in my call to the error sub?

thanks,
glenn
 


glenn,

' Place this code just before the code that fails
On Error Resume Next
...your code here

' Place this code right after the section where it fails.
If err.number <> 0 then
response.write &quot;Err #: &quot; & err.number & &quot;<br>Err Description: &quot; & err.description
response.end
End if

fenghsui_1998

 
Thanks, but that is working already, however, it is inadequate. It doesn't tell me exactly where the error occurs, I can have 100 of these messages throughout the code on my site, how would I know in the log which file it came from, and which error handling code it was from (line # in the code would be helpful.)

glenn
 


Glenn,

You could write a function that if err.number <> 0

1. writes the ASP page to the log
2. writes the err.number
3. writes the err.description
4. clears err.number = err.clear

That's what you would have to do to debug your code.
fengshui_1998
 
penny.gif
penny.gif
 
Thanks for your help, but what I was actually looking for was a way to get all the information, the file name, the line number where the compiler blew up, the actual database error or asp error...actually here is the code...I think this only works with asp3.0 (windows 2000 and up) Maybe some of you can use it as well.

glenn


Set objError = Server.GetLastError()
If Len(CStr(objError.ASPCode)) > 0 Then
strErrorMessage = strErrorMessage + &quot;IIS Error Number :&quot; + objError.ASPCode + &quot;--&quot;
end if
If Len(CStr(objError.Number)) > 0 Then
strErrorMessage = strErrorMessage + &quot;Com Error Number :&quot; +objError.Number + &quot;--&quot;
End If
If Len(CStr(objError.Source)) > 0 Then
strErrorMessage = strErrorMessage + &quot;Error Source :&quot; +objError.Source + &quot;--&quot;
End If
If Len(CStr(objError.File)) > 0 Then
strErrorMessage = strErrorMessage + &quot;File Name :&quot; +cstr(objError.File) + &quot;--&quot;
End If
If Len(CStr(objError.Line)) > 0 Then
strErrorMessage = strErrorMessage + &quot;Error Line :&quot; +CStr(objError.Line) + &quot;--&quot;
End If
If Len(CStr(objError.Description)) > 0 Then

strErrorMessage = strErrorMessage + &quot;Error Description :&quot; +cstr(objError.Description) + &quot;--&quot;
End If
If Len(CStr(objError.ASPDescription)) > 0 Then
strErrorMessage = strErrorMessage + &quot;Full Description :&quot; +cstr(objError.ASPDescription) + &quot;--&quot;
End If

cust_id = session(&quot;cust_id&quot;)
user_id = session(&quot;user_id&quot;)
if cust_id = &quot;&quot; then
cust_id = &quot;unknown customer&quot;
end if
if user_id = &quot;&quot; then
user_id = &quot;unknown user&quot;
end if

sql = &quot;insert into errortable (error_id,APPLICATION_GROUP,APPLICATION_NAME,program_name,subroutine_name,error_message) &quot;
sql = sql + &quot; values &quot;
sql = sql + &quot;(errors_seq.nextval,'app_name',' ERROR HANDLING', '&quot; & Request.ServerVariables(&quot;SCRIPT_NAME&quot;) & &quot;', '&quot;
sql = sql + &quot;cust_id :&quot; & cust_id & &quot; user_id : &quot; & user_id & &quot;', '&quot;
sql = sql + strErrorMessage & &quot;')&quot;


set error_rs = dataconn.execute(sql,,adCmdText)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top