title: Java - TestNG : Why does my Assertion always passes when written within try-catch block
body: <p>I was trying with a simple code using <code>org.testng.Assert</code> to assert 2 use-cases. In the first use-case I am asserting 2 unequal values which <code>Fail</code> correctly. </p>
  
  <p>But in the second use-case when I am asserting 2 unequal values within the try-catch block, the result is always returned as <code>Pass</code></p>
  
  <p>My code is as follows:</p>
  
  <pre><code>package demo;
  import org.testng.Assert;
  import org.testng.annotations.Test;
  public class Q43710035 
  {
  
      @Test
      public void test1() 
      {
          System.out.println("Within test1");
          int a = 12;
          int b =20;
          Assert.assertEquals(a, b);
  
      }
  
      @Test
      public void test2() 
      {
          System.out.println("Within test2");
          int a = 12;
          int b =20;
  
          try 
          {
              Assert.assertEquals(a, b);
          }catch(Throwable t)
          {
              System.out.println("Exception Occurred");
          }
      }
  }
  </code></pre>
  
  <p>The result I am getting is: </p>
  
  <pre><code>Within test1
  Within test2
  Exception Occurred
  PASSED: test2
  FAILED: test1
  java.lang.AssertionError: expected [20] but found [12]
  at org.testng.Assert.fail(Assert.java:94)
  </code></pre>
  
  <p>My question are:</p>
  
  <ol>
  <li>In test2() though the Assertion is failing why doesn't the execution comes out of this <code>Test</code> ?</li>
  <li>In test2() it seems try block is failing, so the execution reaches catch block and <code>Exception Occurred</code> gets printed. Why should <code>try</code> block fail here when the assertion code is getting executed?</li>
  </ol>