Back to notes -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'        Slide program -- Keyboard shortcut: 't'    Demonstrations of try catch.Lecture 2 - slide 14 : 43
Program 5
/* Right, Wrong */
using System;

class TryCatchDemo {
  public static void Main(){
    int i = 5, r = 0, j = 0;

    /*
    r = i / 0;  
    Console.WriteLine("r is {0}", r);   
    */

    try {       
      r = i / j;
      Console.WriteLine("r is {0}", r);
    } catch(DivideByZeroException e){
        Console.WriteLine("r could not be computed");
    }   
  }      
}
 
 
 
 
 
 
 
 
Windows: Compile time error. On MONO: Run time error 
 
 
 
Output: r could not be computed