VB.NET中,抛出Exception时可能没有任何附加信息吗?

2026-05-06 12:241阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计244个文字,预计阅读时间需要1分钟。

VB.NET中,抛出Exception时可能没有任何附加信息吗?

在尝试维护他人代码时,我发现了一个小宝藏:`Catch ex As Exception If Not ex Is Nothing Then ... End If Finally`。这种结构是否在特定时间发生异常我不确定。我应该将这些添加到我的代码中吗?如果尝试了,请告诉我结果。

VB.NET中,抛出Exception时可能没有任何附加信息吗?

在尝试维护别人的代码时,我发现了这个小宝石:

Catch ex As Exception If Not ex Is Nothing Then ... End If Finally

有没有时间发生这种情况我不知道?我应该将这些添加到我的代码中吗?

如果你试试这个:

Try Dim x As Exception = Nothing Throw x Catch ex As Exception Debug.Print(ex.ToString()) End Try

ex将是一个System.NullReferenceException. Throw statement文档没有提到如果传递空引用会发生什么,但OpCodes.Throw文档说:

NullReferenceException is thrown if the object reference is a null reference.

所以,我相信答案是前者永远不会是无.

本文共计244个文字,预计阅读时间需要1分钟。

VB.NET中,抛出Exception时可能没有任何附加信息吗?

在尝试维护他人代码时,我发现了一个小宝藏:`Catch ex As Exception If Not ex Is Nothing Then ... End If Finally`。这种结构是否在特定时间发生异常我不确定。我应该将这些添加到我的代码中吗?如果尝试了,请告诉我结果。

VB.NET中,抛出Exception时可能没有任何附加信息吗?

在尝试维护别人的代码时,我发现了这个小宝石:

Catch ex As Exception If Not ex Is Nothing Then ... End If Finally

有没有时间发生这种情况我不知道?我应该将这些添加到我的代码中吗?

如果你试试这个:

Try Dim x As Exception = Nothing Throw x Catch ex As Exception Debug.Print(ex.ToString()) End Try

ex将是一个System.NullReferenceException. Throw statement文档没有提到如果传递空引用会发生什么,但OpCodes.Throw文档说:

NullReferenceException is thrown if the object reference is a null reference.

所以,我相信答案是前者永远不会是无.