Name

Err.Description Property

Data Subtype

String

Description

A read/write property containing a short string describing a runtime error.

Rules at a Glance

  • When a runtime error occurs, the Description property is automatically assigned the standard description of the error.

  • If there is no error (that is, if the value of Err.Number is 0), the value of the Description property is an empty string.

  • For user-defined errors (that is, for errors that you define in your own scripts), you must assign a string expression to the Description property or the error won’t have an accompanying textual message.

  • You can override the standard description by assigning your own description to the Err object for both VBScript errors and user-defined errors.

Example

This example uses the description parameter of the Err.Raise method to return an error message when validating information from an HTML form. The web page containing the form is:

<HTML>
<HEAD>
<TITLE>Register</TITLE>
</HEAD>
<BODY>
<CENTER><H1>Welcome!</H1></CENTER>
Enter Your Name:
<FORM NAME="frmName" METHOD="POST" ACTION="Err_Desc2.asp" >
<INPUT TYPE="text" NAME="txtName">
<INPUT TYPE="submit">
</FORM>
</BODY>
</HTML>

The source code for Err_Desc2.asp is:

<HTML> <HEAD> <TITLE>Welcome to our Web Page</TITLE> <SCRIPT LANGUAGE="VBSCRIPT" RUNAT="Server"> Function ValidateString(sString) If sString = "" Then Err.Raise 61000,,"<H4>Please press the Back button and enter your name.</H4>" Else ValidateString = sString End If End Function </SCRIPT> </HEAD> <BODY> ...

Get VBScript in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.