Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old March 7th, 2005, 09:18 PM
Levi Hackwith Levi Hackwith is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 7 Levi Hackwith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m
Reputation Power: 0
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.

Reply With Quote
  #2  
Old March 7th, 2005, 09:39 PM
Levi Hackwith Levi Hackwith is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 7 Levi Hackwith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m
Reputation Power: 0
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.

Reply With Quote
  #3  
Old March 8th, 2005, 04:02 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,906 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 8 h 17 m 44 sec
Reputation Power: 1537
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
 

Reply With Quote
  #4  
Old March 8th, 2005, 10:18 AM
Levi Hackwith Levi Hackwith is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 7 Levi Hackwith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m
Reputation Power: 0
Quote:
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:


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.

Reply With Quote
  #5  
Old March 8th, 2005, 01:32 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,906 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 8 h 17 m 44 sec
Reputation Power: 1537
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:
Originally Posted by Microsoft
Remarks

When IIS encounters an error either with compiling or running an .asp file, it will generate a 500;100 custom error. By default all Web sites and applications will transfer processing of a 500;100 custom error to the default .asp file. After a 500;100 custom error is generated, IIS will also create an instance of the ASPError object which describes the error condition. For information on how to use the IIS snap-in to change the .asp file for processing 500;100 custom errors, see Enabling ASP Error Processing.

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.

Reply With Quote
  #6  
Old March 8th, 2005, 01:46 PM
Levi Hackwith Levi Hackwith is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 7 Levi Hackwith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m
Reputation Power: 0
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

Reply With Quote
  #7  
Old March 8th, 2005, 02:31 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,906 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338585 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 8 h 17 m 44 sec
Reputation Power: 1537
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.

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Some Error Trapping Questions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway