?
Solved

How to correctly use "On Error Resume Next" in ASP

Posted on 2007-03-27
9
Medium Priority
?
1,697 Views
Last Modified: 2009-12-16
Hello experts,

Currently I have a custom 500 error page set up in IIS that logs errors.  However whenever an error occurs the page stops processing and the 500 error page is loaded.  I would like to instead use the "On Error Resume Next" method, but I having some problems.

First here is the code from my 500 error page that prints out the error details.  This works correctly - whenever there is a 500 error it prints out the error description, the line, and the column:

Set ASPErr = Server.GetLastError()
response.write("Line: " & ASPErr.Line & "<br>")
response.write("Column: " & ASPErr.Column & "<br>")
response.write("Description: " & ASPErr.Description & "<br>")

Here is the code I am using to implement "On error resume next".  This code is not working.

On Error Resume Next
'database request
If Err.number <> 0 then
    Set ASPErr = Server.GetLastError()      
    response.write("Line: " & ASPErr.Line & "<br>")
    response.write("Column: " & ASPErr.Column & "<br>")
    response.write("Description: " & ASPErr.Description & "<br>")
End If

This code does not work correctly.  It always returns 0 as the error line and -1 as the column number, no matter where the error occurs.  It also does not return the description.

Can anyone tell me what I am doing wrong here?  Is it a mistake in my code?  Why does it work correctly on the custom 500 error page but incorrectly when using "On Error Resume Next"?

Thanks in advance!
0
Comment
Question by:greatseats
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 22

Expert Comment

by:WMIF
ID: 18803861
you shouldnt need the "Set ASPErr = Server.GetLastError()" line in there.  try using the same properties but with the Err object.
0
 

Author Comment

by:greatseats
ID: 18803932
WMIF,

I adjusted my code to read:

If Err.number <> 0 then
    response.write("Line: " & Err.Line & "<br>")
    response.write("Column: " & Err.Column & "<br>")
    response.write("Description: " & Err.Description & "<br>")
End If

The output error description now reads:  "Object doesn't support this property or method".  However that error description is not correct; I get that description for any error, be it an SQL error, Type mismatch, Overflow, etc.

I believe that this error description is in reference to the "Err.Line" and "Err.Column" code; If I remove those two items I get the correct error description for whatever went wrong.  Is there a way to output the error line?
0
 
LVL 22

Expert Comment

by:WMIF
ID: 18803971
what if you write the description property first?
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:greatseats
ID: 18804026
WMIF,

If I write the description property first I get the correct description.  However I get nothing for the  Err.Column and Err.Line values.
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 18804071

Line and Column aren't properties of the Err Object in VbScript. You get:

Description
Source
Number

As well as two methods (Raise and Clear).

This may not help too much as it won't help you find a line number. But that's what you get available to you.

You can find lots more on the Err Object and error handling in general in VbScript here:

http://www.microsoft.com/technet/scriptcenter/resources/scriptshop/shop1205.mspx
http://www.microsoft.com/technet/scriptcenter/resources/scriptshop/shop0106.mspx

Silly titles, but good articles.

Chris
0
 

Author Comment

by:greatseats
ID: 18804347
Chris-Dent,

Is there any way for me to get the line number of the error?
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 2000 total points
ID: 18806434

Only from the log files when it fails completely (or the 500 page if you tell it to).

That's part of the problem with the Err object, it's not all the script processor uses to report a fatal error.

When you start to handle the errors yourself (with On Error ...) you get rid of the fatal error, but for an accurate failure reason you must write in full error handling at every point you think is suspect.

I'm sorry it's not better news, it's something I've struggled with in the past as well. All I can suggest is that you minimize the scope for On Error Resume Next by turning it off afterwards with "On Error Goto 0", either that or write yourself a Subroutine that will report the error and a little information about what called the subroutine (which you would have to hard-code).

Chris
0
 

Author Comment

by:greatseats
ID: 18809483
Chris-Dent,

Thanks for the info.  It looks like the hard-coding method is my best bet.  I was just hoping it wouldn't come to that:-).  Thanks again!
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 18809508

No problem, good luck!

Chris
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Prologue It is often required to host multiple websites on a single instance of IIS, mostly in development environments instead of on production servers. I am sure it is not much a preferred solution on production servers but this is at least a pos…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question