Home arrow ASP arrow Page 2 - Replacing the Error 500 ASP Page

Replacing the Error 500 ASP Page

This article looks at how error information is stored and obtained in ASP 3.0 - the ASPError object, this information is then used in the creation of a new, better error page.

Author Info:
By: Wrox Team
Rating: 5 stars5 stars5 stars5 stars5 stars / 91
January 20, 2003
  1. · Replacing the Error 500 ASP Page
  2. · The ASPError Object
  3. · Editing the ASP Error Page
  4. · Extending the Functionality
  5. · E-Mailing Errors
  6. · SourceSafe Integration
  7. · Conclusion

print this article

Replacing the Error 500 ASP Page - The ASPError Object
(Page 2 of 7 )

In previous versions of ASP (prior to version 3.0, which is included with IIS 5), error handling was a tricky task.

Although JScript has structured error handling, which is in line with the latest languages via try ... catch blocks, the only available option with VBScript was to put an On Error Resume Next before a piece of code, and to then check whether an error occurred after the line using an If Err Then ... construct.

Following any error processing, error-trapping could be disabled using an On Error GoTo 0 statement. When functionality wasn't wrapped in COM components, which are largely developed using languages that support better error handling (such as Visual Basic and C++), many applications have been developed that have a single On Error Resume Next before any processing begins, with no subsequent error trapping or handling rather than trapping errors in such a time-consuming way.

With ASP 3.0, the situation changes a little, and error management becomes slightly more structured. This does not mean that VBScript has proper error handling such as an On Error GoTo Label statement, but a step has been made in the right direction with the inclusion of the ASPError object.

This object is returned by the Server.GetLastError method call, and has the following read-only public members (which are covered in more detail in MSDN):

ASPCodeReturns an error code generated by IIS
NumberReturns the standard COM error code
SourceReturns the actual source code, when available, of the line that caused the error
CategoryIndicates if the source of the error was internal to ASP, the scripting language, or an object
FileIndicates the name of the .asp file that was being processed when the error occurred
LineIndicates the line within the .asp file that generated the error
ColumnIndicates the column position within the .asp file that generated the error
DescriptionReturns a short description of the error
ASPDescriptionReturns a more detailed description of the error if it is an ASP-related error

As can be seen, there is far more information available in this object than in the standard Err object -most notably, the line and column where the error occurred, and an extra description.

Whilst these details are far more useful, there is one fundamental problem; a piece of code such as the one given below will not work:

On Error Resume Next
dblValue = 1/0 '== Will cause a divide by 0 error
Set objError = Server.GetLastError
If objError.Number>0 Then
'Do some error processing
End If

Once an On Error Resume Next statement is used, no errors are raised and objError won't contain any information - the only way to test for an error would be the traditional "If Err.Number<>0 Then ..." statement.

If the On Error Resume Next line was missing, then processing would be transferred to the error page as soon as an error is encountered. This means that the only place that the error object can actually be used is on the error page itself. Control is passed to this page via a Server.Transfer() call as soon as an un-trapped error occurs. If needed, On Error statements can still be made to stop execution from passing to this page.
blog comments powered by Disqus

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials