What is the difference between handling exceptions by catch block directly parent class and subclasses

Viewed 89

I have the following Java code

import org.testng.annotations.Test;

@Test
public void testException(){
    try{
        Assert.assertEquals(1,2);
    } catch(Exception e) {
      e.printStackTrace();
    }
}

When the test is run, the assertion fails and exception is printed as standard output and the TestNG shows the test result as FAILED.

If I catch the same exception using

catch(AssertionError e){
    e.printStackTrace();
}

the exception is printed as error output and the TestNG shows the test result as PASSED. In both cases exception is handled, but what is the difference here?

2 Answers
Related