Err OBJECT IN VBSCRIPT


Err object:

Returns or sets a descriptive string associated with an error.
Syntax:
object.Description [= stringexpression]

object-Always the Err object.
Description-consists of a short description of the error.
stringexpression-A string expression containing a description of the error.

Properties of Err object:

Description-Syntax: object. Description [ =string]
This property returns or sets a string containing a brief textual description of an error.
HelpContext-Syntax: object.HelpContext [ =contextID]
This property is used to set or return a context ID for a Help topic specified with the HelpFile property.

HelpFile-Syntax: object. HelpFile [ = contextID]
This property is used to get or define the path to a Help file.

Number-Syntax: object.Number [ =errnumber]
This property is used to retrieve or set the value that relates to a specific runtime error.

Source-Syntax: object. Source [ =string]
This property lets us determine the object or application that caused an error, and returns a string that contains its Class name or programmatic ID.

Methods of Err object:

Clear-Syntax: object.Clear
This method is used to clear teh settings of the Error object.

Raise-Syntax: object.Raise(number[, source, description, helpfile, helpcontext])
This method is used to generate a VBScript runtime error.

Example:

<html>
<body>
<script language=”vbscript”>
dim numerr, abouterr
On Error Resume Next
Err.Raise 6
numerr = Err.number
abouterr = Err.description
If numerr <> 0 Then
Response.Write "An Error has occured! Error number " numerr " of the type '" abouterr "'."
End If
</script>
</body>
</html>


Output:
"An Error has occured! Error number 6 of the type 'Overflow'."

No comments:

Post a Comment