Learn C#, VB.net with Samples in 1 Day


throw
  1. to signal the occurrence of an unusual exceptions
C# VB.net
using System;
class Program
{
    static void Main()
    {
        int[] ar = { 1, 2, 3 };

        try
        {
            if (ar.Length > 2)
            {
                throw new Exception("Array size Exceeds");
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
        Console.ReadKey();
    }
}                                
Class Program
	Private Shared Sub Main()
		Dim ar As Integer() = {1, 2, 3}

		Try
			If ar.Length > 2 Then
				Throw New Exception("Array size Exceeds")
			End If
		Catch e As Exception
			Console.WriteLine(e.Message)
		End Try
		Console.ReadKey()
	End Sub
End Class
                            

Output:

Array size Exceeds
Test your .net skills with Quiz