Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net VB异常示例消息 在C++中,当我抛出异常时,函数给了我确切的消息,但是在VB中,当我用自定义消息抛出异常并使用Ex.Mead时,除了GM之外,我得到了异常的原始消息。_Vb.net - Fatal编程技术网

Vb.net VB异常示例消息 在C++中,当我抛出异常时,函数给了我确切的消息,但是在VB中,当我用自定义消息抛出异常并使用Ex.Mead时,除了GM之外,我得到了异常的原始消息。

Vb.net VB异常示例消息 在C++中,当我抛出异常时,函数给了我确切的消息,但是在VB中,当我用自定义消息抛出异常并使用Ex.Mead时,除了GM之外,我得到了异常的原始消息。,vb.net,Vb.net,有没有一种简单的方法只显示我的自定义消息 例如: Throw New ArgumentOutOfRangeException("Invalid Range") Catch ex As ArgumentOutOfRangeException 'invalid range MessageBox.Show(ex.Message) End Try 消息输出为: 如果抛出ArgumentOutOfRangeException,则构造函数中的第一个参数是ParamNa

有没有一种简单的方法只显示我的自定义消息

例如:

Throw New ArgumentOutOfRangeException("Invalid Range")

    Catch ex As ArgumentOutOfRangeException 'invalid range

        MessageBox.Show(ex.Message)

    End Try
消息输出为:

如果抛出ArgumentOutOfRangeException,则构造函数中的第一个参数是ParamName而不是Message,而不仅仅是无效范围。因为此异常用于指示参数何时超出范围,而ParamName用于显示所使用的参数。 例如:

如果只想指定消息,则需要编写:

Throw New ArgumentOutOfRangeException(nothing, "Invalid Range")
抛出新ArgumentOutofRangeException Nothing,无效范围“Short and Sweet”。不错。
Throw New ArgumentOutOfRangeException(nothing, "Invalid Range")