ErrObject.Source 屬性

定義

傳回或設定 String 運算式,指定最初產生錯誤的物件或應用程式的名稱。 讀取/寫入

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

屬性值

傳回或設定 String 運算式,指定最初產生錯誤的物件或應用程式的名稱。 讀取/寫入

範例

此範例示範在 Source 一般錯誤處理例程中使用 屬性。 從 引發 Class1錯誤時,字串 "Class1" 會指派給 Source 對象的屬性 Err 。 接著,此字串會顯示在資訊訊息中,指出錯誤的來源和數目。

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

備註

屬性 SourceString 指定表達式,代表產生錯誤的物件;表達式通常是對象的類別名稱或進程標識符。 Source當您的程式代碼無法處理存取物件中產生的錯誤時,請使用 屬性來提供資訊。 例如,如果您存取 Microsoft Excel 併產生 Division by zero 錯誤,Microsoft Excel 會將該錯誤的錯誤碼設定 Err.Number 為錯誤碼,並將 設定 Source 為 “Excel.Application”。

當應用程式從程式代碼產生錯誤時, Source 是應用程式的程式設計標識符。 在類別中, Source 應該包含具有表單 項目名稱。類別。 當您的程式代碼中發生非預期的錯誤時, Source 會自動填入 屬性。 對於模組中的錯誤, Source 包含項目名稱。

適用於

另請參閱