|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Some Error Trapping Questions
Hey guys,
I've a really quick programming question for you. Today, I made some really cool error trapping code in plain ASP. It works great...well, sort of. Here's (in a nutshell) how it works: The code traps an error and then emails me the information about the error. Here's the problem: the only errors it traps are the ones I create using err.raise. I used err.raise to test it. When a real asp error occurs, it just let's it happen. I've implemented the code on the main page of my website (www.levihackwith.com). Here's the code: Code:
<%
if err <> 0 then
dim errorObject
set errorObject = server.GetLastError()
dim message
message = "Levi, " & "<BR><BR>" & "An error occured on your website. Here's the information:" & vbcrlf & vbcrlf &_
"When: " & now & vbcrlf &_
"Where: " & errorObject.file() & "<BR>" &_
"Error Number: " & errorObject.number() & "<BR>" &_
"Error Code: " & errorObject.ASPCode() & "<BR>" &_
"Error Category: " & errorObject.category() & "<BR>" &_
"Description: " & errorObject.description() & "<BR>" &_
"Source Code: " & errorObject.source() & "<BR>" &_
"Line Number: " & errorObject.line() & "<BR>" &_
"Column: " & errorObject.column() & "<BR>" &_
"User Logged In: " & session("username")
Dim objMail
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.MailFormat = 0
objMail.BodyFormat = 0
objMail.From = "ContactBot@LeviHackwith.com"
objMail.To = "levi.hackwith@gmail.com"
objMail.Subject = "Site Error"
objMail.Body = message
objMail.Send
Set objMail = Nothing
%>
<!--#include virtual="/error_pages/error.asp" -->
<%
response.End()
end if
%>
Here's the first few lines of my index page: Code:
<% on error resume next %> <!--#include file = "includes/code_bits/error_trap.asp"--> <!--#include file = "includes/code_bits/title_generator.asp"--> Now when I change the above lines of code to look like this, it catches the error: Code:
<% on error resume next %> <% err.raise 14 %> <!--#include file = "includes/code_bits/error_trap.asp"--> <!--#include file = "includes/code_bits/title_generator.asp"--> Now, I have tried making it so the error_trap.asp code gets included after the title generator code but it still doesn't work. Any suggestions? Thanks for the help. |
|
#2
|
|||
|
|||
|
No worries guys. I got it working. However, all the err object's properties come back blank.
for example, when i tell it to list the error number it returns a blank number. When i ask it the column it gives me an -1. any ideas? thanks again. |
|
#3
|
||||
|
||||
|
the GetLastError would be available only if you set Customized Error Pages of your own. local error object is the reserved word "Err" and it contains error Number and error description:
Code:
If Err.Number<>0 Then
Response.Write("number: "&Err.Number&"<br />")
Response.Write("details: "&Err.Description&"<br />")
End If
|
|
#4
|
|||
|
|||
|
Quote:
I'm afraid i don't quite understand what I have to do to fix the problem. and what about all the other Err object properties like the ones listed at http://www.w3schools.com/asp/asp_ref_error.asp ? Are they useable? Thanks for the help guys. |
|
#5
|
||||
|
||||
|
you can't fix that using the current code... you'll have to change the whole logic.
the information in w3schools is correct, but confusing: they explain the details of the ASPError object itself without mentioning it's available only in special conditions... here is the official documentation: http://www.microsoft.com/windows200...sp/vbob1dtg.htm in there, you have this remark: Quote:
read carefully the page about Enabling ASP Error Processing and you'll be on the correct path. you'll have to move the code you currently use to the Custom Error page. |
|
#6
|
|||
|
|||
|
The info you sent me to makes complete sense. However, could you clarify something? The documentation makes it sound like you route every HTTP error (404, 500 etc) to an asp error handling file. What about errors that asp 'causes like a bad database connection or syntax error? Does it work for those too?
So far what I've gathered is that I have to route all page errors to my error_trap code and then the info will fill in correctly. Is that right? Thanks for the help man. Levi |
|
#7
|
||||
|
||||
|
all scripting-related errors are called "500;100 errors" and you have one single page to deal with them. other http errors e.g. 404 are not related to code and you won't have the ASPError object available.
|
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > Some Error Trapping Questions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|