Error Handling Using Try, Catch And Finally Blocks In C#

  1. using System;  
  2. class Program {  
  3.     static void Main(string[] args) {  
  4.         int[] a = new int[3];  
  5.         int n = args.Length;  
  6.         try {  
  7.             if (n == 0) {  
  8.                 int d = 10 / (n);  
  9.             }  
  10.             if (n == 1) {  
  11.                 a[4] = 6;  
  12.             }  
  13.         } catch (IndexOutOfRangeException e) {  
  14.             Console.WriteLine("Exception" + e);  
  15.         } catch (DivideByZeroException e) {  
  16.             Console.WriteLine("DivideByZeroException" + e);  
  17.         } finally {  
  18.             Console.WriteLine("finally block :: End of Program");  
  19.         }  
  20.         Console.ReadKey();  
  21.     }  
  22. }