VB.NET中,抛出Exception时可能没有任何附加信息吗?
- 内容介绍
- 文章标签
- 相关推荐
本文共计244个文字,预计阅读时间需要1分钟。
在尝试维护他人代码时,我发现了一个小宝藏:`Catch ex As Exception If Not ex Is Nothing Then ... End If Finally`。这种结构是否在特定时间发生异常我不确定。我应该将这些添加到我的代码中吗?如果尝试了,请告诉我结果。
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分钟。
在尝试维护他人代码时,我发现了一个小宝藏:`Catch ex As Exception If Not ex Is Nothing Then ... End If Finally`。这种结构是否在特定时间发生异常我不确定。我应该将这些添加到我的代码中吗?如果尝试了,请告诉我结果。
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.
所以,我相信答案是前者永远不会是无.

