public class Test{
public static void main(String args[]){
try{
int data=25/0;
System.out.println(data);
}
catch( ArithmeticException e)
{
System.out.println(e);
}
}
}
o/p:java.lang.ArithmeticException: / by zero
In this code even if I catch the exception using the ArithmaticException class or directly the Exception class, the o/p is the same. Then why do we use the subclasses in different catch statements instead of directly using Exception class everytime?