Mega Code Archive

 
Categories / VB.Net / Development
 

ArgumentException Class is thrown when one of the arguments provided to a method is not valid

Public Class App     Public Shared Sub Main()         Console.WriteLine("10 divided by 2 is {0}", DivideByTwo(10))         Try             Console.WriteLine("7 divided by 2 is {0}", DivideByTwo(7))         Catch Ex As ArgumentException             Console.WriteLine("7 is not divided by 2 integrally.")         End Try     End Sub     Private Shared Function DivideByTwo(ByVal num As Integer) As Integer         If ((num And 1)  = 1) Then             Throw New ArgumentException("Number must be even", "num")         End If         Return (num / 2)     End Function End Class