ASP
  Home arrow ASP arrow Page 2 - Replacing the Error 500 ASP Page
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Replacing the Error 500 ASP Page
By: Wrox Team
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 29
    2003-01-20

    Table of Contents:
  • Replacing the Error 500 ASP Page
  • The ASPError Object
  • Editing the ASP Error Page
  • Extending the Functionality
  • E-Mailing Errors
  • SourceSafe Integration
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

    More ASP Articles
    More By Wrox Team


     

    ASP ARTICLES

    - 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...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek