ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash





ASP Source Code:
<%
' Error handling in VBScript is relatively primitive.
' There are basically just two options:
'
' On Error Goto 0 (the default)
'   This causes execution to break when an error happens and
'   show an error message.
' On Error Resume Next
'   This causes the script to continue execution starting with
'   the next line after the error.
'
' By itself this can hardly be called error handling, but VBScript
' has a built in Err object which helps some.  When "On Error
' Resume Next" is enabled, the properties of the Err object are
' automatically populated with details of the errors that have
' occurred.
' Tell our script to continue executing even if an error occurs:
On Error Resume Next
' Some code that is intentionally wrong:
Dim cnnTest
Set cnnTest = Server.CreateObject("ADODB.ThisObjectDoesntExist")
Set cnnTest = Nothing
%>
<p>
Error details:
</p>
<table border="1">
	<tr>
		<td>Err.Source</td>
		<td><%= Err.Source %></td>
	</tr>
	<tr>
		<td>Err.Number</td>
		<td><%= Err.Number %></td>
	</tr>
	<tr>
		<td>Err.Description</td>
		<td><%= Err.Description %></td>
	</tr>
</table>
<%
' You can clear the error information in the Err object by calling
' the clear method:
Err.Clear
' You can also raise an error of your own if you need to:
Err.Raise 1, "ASP 101", "This is a custom error that I raised!"
%>
<p>
Error details:
</p>
<table border="1">
	<tr>
		<td>Err.Source</td>
		<td><%= Err.Source %></td>
	</tr>
	<tr>
		<td>Err.Number</td>
		<td><%= Err.Number %></td>
	</tr>
	<tr>
		<td>Err.Description</td>
		<td><%= Err.Description %></td>
	</tr>
</table>
<%
' Turn "error-handling" back off... after the next line the
' script will break as normal if any errors happen.
On Error Goto 0
' Note that what we've just done is pretty pointless.  If we
' wanted our users to see the error details then we just wouldn't
' handle the errors at all.  But in the real world you probably
' wouldn't just print them out.  You can then log these to a file,
' send them to someone via email, or do whatever else you might
' want to do with them.  I tend to display a generic message
' something like "We're sorry, but there has been an error
' processing your request.  The webmaster has been notified and
' will look into the problem as soon as possible.  Please try your
' request later." to the end user and then send an email to
' myself containing the script name and the error details so I can
' look into the problem.
'=================================================================
' Starting with ASP 3.0 there is a another method for handling
' run-time errors: the ASPError object.  It's used to centrally
' handle errors for an entire site by setting up a custom error
' page.  You can find more information about this type of error
' handling here:
'
' http://www.asp101.com/articles/carvin/errlog/default.asp
' http://www.asp101.com/articles/stuart/asperrormsgs/default.asp
'=================================================================
%>

Back the the Sample Output

Back to the Sample Index


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers