title: finally block in c#
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4193493/finally-block-not-running">Finally Block Not Running??</a>  </p>
  </blockquote>
  
  
  
  <p>I have a question regarding finally block in c#. 
  I wrote a small sample code:</p>
  
  <pre><code>public class MyType
  {
      public void foo()
      {
          try
          {
              Console.WriteLine("Throw NullReferenceException?");
              string s = Console.ReadLine();
              if (s == "Y")
                  throw new NullReferenceException();
              else
                  throw new ArgumentException();          
          }
          catch (NullReferenceException)
          {
              Console.WriteLine("NullReferenceException was caught!");
          }
          finally
          {
              Console.WriteLine("finally block");
          }
      }
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          MyType t = new MyType();
          t.foo();
      }
  }
  </code></pre>
  
  <p>As I far as I know, finally block suppose to run deterministicly, whether or not an exception was thrown. 
  Now, if the user enters "Y" - NullReferenceException is thrown, execution moves to the catch clock and then to the finally block as I expected.
  But if the input is something else - ArgumentException is thrown. There is no suitable catch block to catch this exception, so I thought execution should move the the finally block - but it doesnt. Could someone please explain me why?</p>
  
  <p>thanks everyone :)</p>