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
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.
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
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)