本文整理匯總了VB.NET中System.ArgumentException類的典型用法代碼示例。如果您正苦於以下問題:VB.NET ArgumentException類的具體用法?VB.NET ArgumentException怎麽用?VB.NET ArgumentException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ArgumentException類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
Public Class Example
Public Shared Sub Main()
' Define some integers for a division operation.
Dim values() As Integer = { 10, 7 }
For Each value In values
Try
Console.WriteLine("{0} divided by 2 is {1}", value, DivideByTwo(value))
Catch e As ArgumentException
Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message)
End Try
Console.WriteLine()
Next
End Sub
Private Shared Function DivideByTwo(ByVal num As Integer) As Integer
' If num is an odd number, throw an ArgumentException.
If (num And 1) = 1 Then
Throw New ArgumentException(String.Format("{0} is not an even number", num),
"num")
End If
Return num \ 2
End Function
End Class
輸出:
10 divided by 2 is 5 ArgumentException: 7 is not an even number Parameter name: num