Compartilhar via


Source Property (Err Object) 

Returns or sets a String expression specifying the name of the object or application that originally generated the error. Read/write.

Public Property Source() As String 

Remarks

The Source property specifies a String expression representing the object that generated the error; the expression is usually the object's class name or process ID. Use the Source property to provide 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".

When the application is generating an error from code, Source is your application's programmatic ID. Within a class, Source should contain a name having the form project.class. When an unexpected error occurs in your code, the Source property is automatically filled in. For errors in a module, Source contains the project name.

Example

This example demonstrates the use of the Source property in a typical error-handling routine. When an error is raised from Class1, the string "Class1" is assigned to the Source property of the Err object. This string is then displayed in an informative message indicating the source and number of the error.

Public Class Class1
  Public Sub MySub()
      On Error Resume Next
      Err.Raise(60000, "Class1")
      MsgBox(Err.Source & " caused an error of type " & Err.Number)
  End Sub
End Class

Requirements

Namespace: Microsoft.VisualBasic

Module: ErrObject

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

See Also

Reference

Err Object (Visual Basic)
Description Property (Err Object)
ErrorToString Function
GetObject Function (Visual Basic)
HelpContext Property (Err Object)
HelpContext Property (Err Object)
HelpFile Property (Err Object)
LastDllError Property (Err Object)
Number Property (Err Object)
On Error Statement (Visual Basic)