Tips Station Asp.net Article Seo Articles
Tutorials Code Samples
›  Home
›  Mission
›  About us
›  Contact Us
›  Feedback
›  Terms & Condition
Asp Articles
IT Solutions
 
› ASP.NET

› Programming Tips

› Ajax

› Asp

› ADO.NET

› Databases

› SEO

› CSS And Designing

› Php

 
Most Viewed Articles
 
› Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

› Change theme dynamically without page refresh in ASP.NET

› Install AJAX On Machines Running Visual Studio 2005

› Creating Pretty Popups Using AJAX

› Simple ASP Image Resize Function

› SQL Server Performance Counters

› ASP.Net Interview Questions And Their Answers

› Encode Url using ASP

› Difference Between DataGrid and GridView in Asp.Net

› Select Specific Value WithIn Drop Down List Or Radio Button List

more...
 
 
Home> Asp
 
Trapping Errors with the Err Object in ASP
 

Undoubtedly in your code writing experience you will generate an error or two (maybe more). In this How To I will explain how to trap errors and use them to your advantage. First a little about the Err Object.

Err Object Properties
Number
Number of the error generated (helpful to know for trapping)
Description
Description of the error
Source
The object or application that was the source of the error
HelpContext
Context ID for the help file topic
HelpFile
File and path to help file

Syntax:

Check to see that Err.Number is greater than 0.

If Err.Number > 0 Then
     'Some error handling code (print out #, description, custom message, etc.)
End If

Here is an example of trying to access a subscript of an array that is out of range (invalid).

myArr = Array("one","two","three")
Response.Write("Element #3 is " & myArr(3) & "<br>")

Result:

Microsoft VBScript runtime error '800a0009'

Subscript out of range: '[number: 3]'

/test.asp, line 8

Not very nice is it? We can trap this error and print out a nice error message.

myArr = Array("one","two","three")
Response.Write("Element #3 is " & myArr(3) & "<br>")

If Err.Number > 0 Then
     Response.Write("Error #" & Err.Number & "<br>")
     Response.Write("Error Source: " & Err.Source & "<br>")
     Response.Write("Error Description: " & Err.Description & "<br>")
End If

Result:

Error #9
Error Source: Microsoft VBScript runtime error
Error Description: Subscript out of range

The result is much easier to read. You can apply this to any code that you write. If you are generating an error and don't like what you are getting back, you can add the above code to help explain the error to you or report an error nicely to your users.
 
 
Vrp Technologies
 
Serversea Hosting
 
 
Latest Articles
 
› Sending SMS With PHP

› MySQL Join Tutorial

› Make An RSS Feed Using PHP

› Intro To Object: Option Variables

› Design An Online Chat Room With PHP And MySQL

› Create Tell A Friend Script With HTML & PHP

› Benchmark And Optimize PHP Script Speed

› What Kind of DBA Are You?

› SQL Server Performance Counters

› SQL Server Performance Tips

more...
 
Random Articles
 
› Creating Pretty Popups Using AJAX

› Add a Confirmation popup to a Button in Asp.Net

› Displaying an RSS Feed using ASP

› Discovering Your Google PR (Page Rank) Value

› Your New Website Is Inside

› Working with DataSet Objects and XML

› What Are Active Server Pages (ASP)?

› Alternating Row Colors

› Simple ASP Image Resize Function

› UpdatePanel control in Asp.net Ajax

more...
 
Home Mission About us Contact us Feedback Terms Conditions
2008 © Copyright TipsStation. All rights reserved.