當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET Exception.HResult屬性代碼示例

本文整理匯總了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
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:46,代碼來源:Exception.HResult

輸出:

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()


注:本文中的System.Exception.HResult屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。