Επεξεργασία

Κοινή χρήση μέσω


ErrObject.Source Property

Definition

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

public:
 property System::String ^ Source { System::String ^ get(); void set(System::String ^ value); };
public string Source { get; set; }
member this.Source : string with get, set
Public Property Source As String

Property Value

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

Examples

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

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.

Applies to

See also