Raise 方法

生成运行时错误。

语法

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

注:

helpfile 和 helpcontext 是可选的,不受支持。

参数

  • Object必需。始终为 Err 对象
  • Number必需。标识错误性质的长整型子类型。
  • Source可选。用于命名最初生成错误的对象或应用程序的字符串表达式。为自动化对象设置此属性时,请使用 project.class 格式。
  • Description可选。描述错误的字符串表达式。如果未指定,则检查 number 中的值。如果它可以映射到 BSL 运行时错误代码,则使用 BSL 提供的字符串作为 description。如果没有与 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