title: How to catch an Exception in test class which is thrown by another class?
body: <p>I have a window form with one button and I am trying to test it with codedUitest. I want the test to fail if any exception is thrown but in the test class it doesn't catch the exception.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public void button1_Click(object sender, EventArgs e)
  { 
      double[] dummy = new double[1];
      int i = 1;
  
      if (i &gt; 0)
      {
          throw new System.IndexOutOfRangeException("index parameter is out of range.");      
      }
      else
      {             
          dummy[i] = 6;  
      }
  }
  </code></pre>
  
  <p>The test method is:</p>
  
  <pre><code>public void CodedUITestMethod1()
  {
      try
      {
          this.UIMap.TryBtn1();
      }
      catch (IndexOutOfRangeException)
      {
          Assert.Fail();
      }
  }
  </code></pre>