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


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

本文整理匯總了VB.NET中System.Exception.Data屬性的典型用法代碼示例。如果您正苦於以下問題:VB.NET Exception.Data屬性的具體用法?VB.NET Exception.Data怎麽用?VB.NET Exception.Data使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在System.Exception的用法示例。


在下文中一共展示了Exception.Data屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Example

' 導入命名空間
Imports System.Collections

Module Example
   Public Sub Main()
      Console.WriteLine()
      Console.WriteLine("Exception with some extra information...")
      RunTest(False)
      Console.WriteLine()
      Console.WriteLine("Exception with all extra information...")
      RunTest(True)
   End Sub

   Public Sub RunTest(displayDetails As Boolean)
      Try
         NestedRoutine1(displayDetails)
      Catch e As Exception
         Console.WriteLine("An exception was thrown.")
         Console.WriteLine(e.Message)
         If e.Data.Count > 0 Then
            Console.WriteLine("  Extra details:")
            For Each de As DictionaryEntry In e.Data
               Console.WriteLine("    Key: {0,-20}      Value: {1}",
                                 "'" + de.Key.ToString() + "'", de.Value)
            Next
         End If 
      End Try 
   End Sub 

   Public Sub NestedRoutine1(displayDetails As Boolean)
      Try
         NestedRoutine2(displayDetails)
      Catch e As Exception
         e.Data("ExtraInfo") = "Information from NestedRoutine1."
         e.Data.Add("MoreExtraInfo", "More information from NestedRoutine1.")
         Throw e
      End Try 
   End Sub

   Public Sub NestedRoutine2(displayDetails As Boolean)
      Dim e As New Exception("This statement is the original exception message.")
      If displayDetails Then 
         Dim s As String = "Information from NestedRoutine2." 
         Dim i As Integer = -903
         Dim dt As DateTime = DateTime.Now
         e.Data.Add("stringInfo", s)
         e.Data("IntInfo") = i
         e.Data("DateTimeInfo") = dt
      End If 
      Throw e
   End Sub 
End Module
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:52,代碼來源:Exception.Data

輸出:

Exception with some extra information...
An exception was thrown.
This statement is the original exception message.
Extra details:
Key: 'ExtraInfo'               Value: Information from NestedRoutine1.
Key: 'MoreExtraInfo'           Value: More information from NestedRoutine1.

Exception with all extra information...
An exception was thrown.
This statement is the original exception message.
Extra details:
Key: 'stringInfo'              Value: Information from NestedRoutine2.
Key: 'IntInfo'                 Value: -903
Key: 'DateTimeInfo'            Value: 7/29/2013 10:50:13 AM
Key: 'ExtraInfo'               Value: Information from NestedRoutine1.
Key: 'MoreExtraInfo'           Value: More information from NestedRoutine1.


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