Throw statement in c#

Usually the throw statement is used with try-catch or try-finally statements.
You can also rethrow a caught exception using the throw statement

public class ThrowTest2
{

    static int GetNumber(int index)
    {
        int[] nums = { 300, 600, 900 };
        if (index > nums.Length)
        {
            throw new IndexOutOfRangeException();
        }
        return nums[index];

    }
    static void Main() 
    {
        int result = GetNumber(3);

    }
}
/*
    Output:
    The System.IndexOutOfRangeException exception occurs.
*/

Comments

Popular posts from this blog

Brother printer password reset using telnet

How to adjust the brightness in Samsung 19" SyncMaster SA100 LED monitor?

Samsung SA100 Monitor Brightness Adjustment Tool