Back to slide -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'  Annotated program -- Keyboard shortcut: 't'    exception/finally/prog.cs - Illustration of try-catch-finally.Lecture 9 - slide 24 : 30
Program 1

using System;

class FinallyDemo{

  internal enum Control {Returning, Jumping, Continuing, Breaking,   
                         Throwing, Normal}                           

  public static void M(Control reason){
    for(int i = 1; i <= 1; i++)  // a single iteration               
      try{                                                           
        Console.WriteLine("\nEnter try: {0}", reason);
        if (reason == Control.Returning) return;
        else if (reason == Control.Jumping) goto finish;
        else if (reason == Control.Continuing) continue;
        else if (reason == Control.Breaking) break;
        else if (reason == Control.Throwing) throw new Exception();
        Console.WriteLine("Inside try");        
      }
      catch(Exception){                                              
        Console.WriteLine("Inside catch");                           
      }  
      finally{                                                       
        Console.WriteLine("Inside finally");                         
      }
    finish: return;
  }

  public static void Main(){
    for(int i = 0; i <= 5; i++)                                      
      M((Control)i);                                                 
  }
}