本文整理汇总了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