Compartilhar via


Source Property (VBScript)

Returns or sets the name of the object or application that originally generated the error.

object.Source [= stringexpression]

Arguments

  • object
    Always the Err object.

  • stringexpression
    A string expression representing the application that generated the error.

Remarks

The Source property specifies a string expression that is usually the class name or programmatic ID of the object that caused the error. Use Source to provide your users with information when your code is unable to handle an error generated in an accessed object. For example, if you access Microsoft Excel and it generates a Division by zero error, Microsoft Excel sets Err.Number to its error code for that error and sets Source to Excel.Application. Note that if the error is generated in another object called by Microsoft Excel, Excel intercepts the error and sets Err.Number to its own code for Division by zero. However, it leaves the other Err object (including Source) as set by the object that generated the error.

Source always contains the name of the object that originally generated the error — your code can try to handle the error according to the error documentation of the object you accessed. If your error handler fails, you can use the Err object information to describe the error to your user, using Source and the other Err to inform the user which object originally caused the error, its description of the error, and so forth.

When generating an error from code, Source is your application's programmatic ID.

The following code illustrates use of the Source property.

On Error Resume Next
Err.Raise 6   ' Raise an overflow error.
MsgBox ("Error # " & CStr(Err.Number) & " " & Err.Description & "  Source: " & Err.Source)
Err.Clear   ' Clear the error.

Requirements

Version 1

Applies To: Err Object (VBScript)

See Also

Reference

Description Property (VBScript)

Err Object (VBScript)

HelpContext Property

HelpFile Property (VBScript)

Number Property (VBScript)

On Error Statement

Change History

Date

History

Reason

March 2009

Made minor change to output of example.

Content bug fix.