Yurttas/PL/OOL/CS/F/08/01/E11.cs

 1/**
 2 *  Copyright(C) 2004
 3 *  All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4 *
 5 *  Permission to use, copy, modify, and distribute this
 6 *  software and its documentation for EDUCATIONAL purposes
 7 *  and without fee is hereby granted provided that this
 8 *  copyright notice appears in all copies.
 9 *
10 *  @date   : January 1, 2004.
11 *  @authorĀ : Salih Yurttas.
12 */
13
14
15using System;
16using System.IO;
17
18public class E11
19{
20  private const int N=4;
21
22  public static void Main(string[] args) {
23    int[] A = new int[N];
24
25    for(int i=0; i<N; i++)
26      A[i] = i;
27
28    int K = N;
29
30    bool done = false;
31    while(!done)
32    {
33      try
34      {
35        Console.WriteLine();
36        for(int i=0; i<=K; ++i)     // this error is intentional
37          Console.WriteLine(A[i]);  // to demonstrate exception
38        done = true;
39      }
40      catch(System.IndexOutOfRangeException e)
41      {
42        Console.WriteLine("Caught " + e.GetType() + " " + e.Message);
43        --K;
44      }
45    }
46  }
47}