The task states to create 2 classes: in the 1st, create and initialize an array of 10 elements of type int, the default constructor and the indexer; in the 2nd class - Main, in which to demonstrate the situation of going beyond the boundaries of the array. It is necessary to intercept and process an exception in the indexer . Help, how to catch the exception?
class B { private int[] a = new int[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; public int this[int i] { get { if (i >= 0 && i <= 10) return a[i]; else throw new IndexOutOfRangeException(); } set { if (i >= 0 && i <= 10) a[i] = value; else throw new IndexOutOfRangeException(); } } } class MainClass { public static void Main(string[] args) { B bi = new B(); for (int i = 0; i <= 10; i++) {Console.WriteLine(bi[i]);} } }