Raise 方法

產生執行時期錯誤。

語法

object.Raise(number, source, description, helpfile, helpcontext)

註:

helpfile、helpcontext 為選擇性且不受支援。

引數

  • Object必要。一律是 Err 物件
  • Number必要。識別錯誤性質的 Long 整數子類型。
  • Source選擇性。命名最初產生錯誤之物件或應用程式的字串表示式。為 Automation 物件設定此特性時,請使用 project.class 格式。
  • Description選擇性。描述錯誤的字串表示式。如果未指定,則會檢查 number 中的值。如果可以對映至 BSL 執行時期錯誤代碼,則會使用 BSL 提供的字串作為描述。如果沒有與 number 對應的 BSL 錯誤,則會使用一般錯誤訊息。
  • Helpfile選擇性。指向可找到此錯誤說明之說明檔的完整路徑。如果未指定,BSL 會使用 BSL 說明檔的完整磁碟機、路徑和檔案名稱。
  • Helpcontext選擇性。識別 helpfile 中針對此錯誤提供說明之主題的環境定義 ID。如果省略,則會使用與 number 特性對應、針對此錯誤的 BSL 說明檔環境定義 ID (如果有的話)。

備註

除了 number 之外,所有引數都是選擇性的。不過,如果您在未指定某些引數的情況下使用 Raise,而 Err 物件的特性設定值中包含尚未清除的值,則這些值將成為錯誤的值。

下列範例說明 Raise 方法的用法。

範例 1

Sub RaiseOverflowError()
On Error Resume Next          ' Enable error handling.
Err.Raise 6                   ' Raise an overflow error.
Err.Clear                     ' Clear the error.
End Sub
'Output: Number: 6, Description: Overflow

範例 2

Sub RaiseCustomError()
On Error Resume Next          ' Enable error handling.
Err.Raise 1000, "MyApp", "A custom error has occurred."
Err.Clear                     ' Clear the error.
End Sub
'Output: Number: 1000, Description: A custom error has occurred., Source: MyApp