SunQuest
 
       ASP Code
  Home arrow ASP Code arrow My error coding technique in ASP
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 CODE

My error coding technique in ASP
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    1999-09-01

    Table of Contents:

    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

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    When error coding in ASP it’s not as rich an environment as other environments.    I really only reports that there was an error with some Numbers and Descriptions.   There is only a few way's I've found to report these errors back to the end user.   I've seen numerous ways of doing it but found this way the most graceful.     Remember you have to explicitly check after everything that might cause an error.  The main ones I've experiences are database openings and recordset openings & updates.  Here is the sample code I use to check for errors and then redirect them to the error page and record the error into a database..   Note that all my error checking is done before the <html> header is written so if there is an error it can redirect the page without getting an error of Heading already written to the client.  If the html header has been sent to the client you can't do a response.redirect command.

    Page 1 A sample Active Server Page form you would use to submit data

    <html>

    <head>
    <title>Enter some data into the field</title>
    </head>

    <body>

    <p>Enter some data into the field.&nbsp; This form is nothing more than representing a
    form you would use in real life to submit some data to an ASP page.&nbsp;&nbsp; Note this
    isn't going to enter the data into database but it will record the error on an Error page
    and then the some information about the Error.&nbsp; &nbsp; </p>

    <form method="POST" action="error2.asp" name="form1">
    <div align="left"><table border="1" width="340" height="35">
    <tr>
    <td width="143" height="11">Favorite Computer</td>
    <td width="185" height="11"><input type="text" name="T1" size="20"></td>
    </tr>
    <tr>
    <td width="143" height="12">Favorite Game: </td>
    <td width="185" height="12"><input type="text" name="T2" size="20"></td>
    </tr>
    </table>
    </div><p>:<input type="submit" value="Submit" name="B1"><input type="reset" value="Reset"
    name="B2"></p>
    </form>
    </body>
    </html>

    Page 2 the form that is being submitted to and also generates the error that
    redirects it to the Standard Error Page (Which is Page 3 in this example)

    <%@ Language="vbscript"%>
    <%
    'Hold the page in memory until response.flush command is issued or the </html> tag is processed.
    Response.buffer = True

    'This forces the page to continue to process even though there was an error.
    On Error Resume Next

    'Declare all variables
    dim conn
    dim rs
    set conn = server.createobject("adodb.connection")
    conn.open "Example_DSN"

    'Standard Error coding if the database won't open an error number will return something else but zero
    'I then capture the error number and description and is passed using the querystring method
    'Note the description is using the Server.URLEncode function ('This will fill any spaces in the description with
    'the correct HTML code

    If err.number <> 0 Then
    Response.Redirect "Error3.asp?number=" & err.Number & "&desc=" & Server.URLEncode(err.description)
    End If
    set rs = server.createobject("adodb.recordset")
    rs.open "TableName" conn 3 3
    'Explicitly checks to see if there is a problem opening the table
    If err.number <> 0 Then
    Response.Redirect "Error3.asp?number=" & err.Number & "&desc=" & Server.URLEncode(err.description)
    End If

    rs.addnew
    rs("field1") = request.form("field1")
    rs("field2") = request.form("field2")
    rs.update

    'Explicitly checks to see if there is a problem updating the record
    If err.number <> 0 Then
    Response.Redirect "Error3.asp?number=" & err.Number & "&desc=" & Server.URLEncode(err.description)
    End If
    rs.close
    conn.close
    set rs = nothing
    set conn = nothing
    %>
    <html>
    <head>
    <title>Records been added</title>
    </head>

    <body>

    <p>Your record has been added to the database!</p>
    </body>
    </html>

    Standard Error coding page I use in most all my apps!  You also could easily create some kind of database connection and report the errors your getting!

    <%@ language="vbscript"%>
    <%
    'buffers the page on the server
    Response.Buffer = True

    'Declare variables
    dim strNumber
    dim strdesc
    dim conn
    dim rs

    'sets a local variable to the connection string

    strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("error.mdb")

    'Place values that are in the URL into local variables
    strNumber = request("Number")
    strDesc = request("Desc")

    'Opens the connection string and recordset object to record the error in a database

    set conn = server.createobject("adodb.connection")
    conn.open strconn
    set rs = server.createobject("adodb.recordset")
    rs.open "tblError", conn, 2,  2
    rs.addnew
    rs("ErrNumber") = strNumber
    rs("ErrDesc") = strDesc
    rs("timeoccurred") = now()
    rs.update
    rs.movelast

    'Puts the generated ID into a local variable
    strID = rs("id")
    rs.close
    set rs = nothing
    conn.close
    set conn = nothing

    'Clear errors collections
    err.clear

    %> </p>

    <html>
    <head>
    <title>Error page</title>
    </head>
    <body>

    <h1>An Error has occurred</h1>
    'Writes out the generated Number that is received from the database
    'Idea you also could format an email message with this id to report the error to someone

    <h2>Error ID is:<% = strID %></h2>

    <h3>The Error Number is:</h3>
    <i><% = strNumber %>
    </i>

    <h3>The Error Description is:</h3>
    <i><% = strDesc %>
    </i>

    <h3>Please report this error to the webmaster</h3>
    <b><a href="mailto:webmaster@someurl.com">

    <p>Click here to send an email please report the Error Number and Description</a></b> </p>
    </body>
    </html>


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP Code Articles
    More By aspfree

     

    IBM® developerWorks developerWorks - FREE Tools!


    IBM – Taking Web 2.0 to Work

    You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    FREE! Go There Now!


    NEW! A Layered approach to delivering security-rich Web applications

    As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper.
    FREE! Go There Now!


    NEW! Application Development Tools for the Mainframe Developer

    You probably have thousands of lines of COBOL code loaded with business intelligence and being used to run your business, along with an army of developers maintaining these applications. Learn how to prepare your applications and developers so you can keep that competitive edge and move to a service-oriented architecture with the IBM Rational Enterprise Modernization solutions. Replay is available for 9 months.
    FREE! Go There Now!


    NEW! Develop Systems Software Assets with IBM Rational Asset Manager

    Join us for this on demand webcast to learn about developing complex systems more quickly and efficiently. We'll cover market drivers for developing, governing and reusing systems software assets and how you can develop system software assets with Rational Asset Manager.
    FREE! Go There Now!


    NEW! Download the free Web Application Security eKit

    Discover how IBM Rational AppScan Standard Edition can help you detext vulnerabilities in your web applications in the Web Application Security eKit. IBM Rational AppScan is a leading suite of automated web application security solutions that scan and test for common Web application vulnerabilities. The new Web Application Security eKit provides you with valuable resources, including white papers, demos, and additional information on the benefits of testing your Web applications.
    FREE! Go There Now!


    NEW! Evaluate IBM Rational Software Analyzer V7.0

    Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle.
    FREE! Go There Now!


    NEW! Hello World: Monitor a simple business process using WebSphere Business Monitor V6.0.2

    This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product.
    FREE! Go There Now!


    NEW! Hello World: WebSphere Service Registry and Repository

    Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services.
    FREE! Go There Now!


    NEW! Rational 'Talks to You' Teleconference Series

    This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today!
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Performance Tester V7.0.1

    Get a free trial download of the latest version of IBM Rational Performance Tester V7.0.1, a load and performance testing solution for teams concerned about the scalability of their Web-based applications. Combining multiple ease-of-use features with granular detail, Rational Performance Tester simplifies the test-creation, load-generation and data-collection processes that help teams ensure the ability of their applications to accommodate required user loads.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP CODE ARTICLES

    - ASP Forms
    - ASP: The Beginning
    - Getting Remote Files With ASP Continued
    - Inbox and Outbox Manipulation in ASP
    - Relational DropDownList Using VB.NET
    - Ad Tracking URL Hits
    - Use ViewState to display one record per page...
    - Send Email using ASP.NET formatted in HTML
    - ASP File Explorer
    - ASP/XML Interview questions by Srivatsan Sri...
    - Various methods of setting Date values to a ...
    - Conditional DataGrid Item and using checkbox...
    - Fill .NET Listbox with SQL DataReader
    - Filling Dropdown box using Code-Behinds in C#
    - FLAMES code sample written in .NET What is F...

    Click Here




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