本文整理汇总了VB.NET中System.Exception.HResult属性的典型用法代码示例。如果您正苦于以下问题:VB.NET Exception.HResult属性的具体用法?VB.NET Exception.HResult怎么用?VB.NET Exception.HResult使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Exception
的用法示例。
在下文中一共展示了Exception.HResult属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: New
' Example for the Exception.HResult property.
Namespace NDP_UE_VB
' Create the derived exception class.
Class SecondLevelException
Inherits Exception
Private Const SecondLevelHResult As Integer = &H81234567
' Set HResult for this exception, and include it in
' the exception message.
Public Sub New(message As String, inner As Exception)
MyBase.New( String.Format( "(HRESULT:0x{1:X8}) {0}", _
message, SecondLevelHResult ), inner )
HResult = SecondLevelHResult
End Sub
End Class
Module HResultDemo
Sub Main()
Console.WriteLine( _
"This example of Exception.HResult " & _
"generates the following output." & vbCrLf )
' This function forces a division by 0 and throws
' a second exception.
Try
Try
Dim zero As Integer = 0
Dim ecks As Integer = 1 \ zero
Catch ex As Exception
Throw New SecondLevelException( _
"Forced a division by 0 and threw " & _
"a second exception.", ex )
End Try
Catch ex As Exception
Console.WriteLine( ex.ToString( ) )
End Try
End Sub
End Module ' HResultDemo
End Namespace ' NDP_UE_VB
输出:
NDP_UE_VB.SecondLevelException: (HRESULT:0x81234567) Forced a division by 0 a nd threw a second exception. ---> System.DivideByZeroException: Attempted to divide by zero. at NDP_UE_VB.HResultDemo.Main() --- End of inner exception stack trace --- at NDP_UE_VB.HResultDemo.Main()