Probably a newbie question, but everyone seems to use e.printStackTrace(), but I have always used System.out.println(e) when exception handling. What i
Bellow Program show the difference details
System.out.println(e); :- only showing the exception. e.g.java.lang.ArithmeticException: / by zero e.printStackTrace(); :- showing the details of exception and where to cause exception in program with line number e.g. java.lang.ArithmeticException: / by zero at test.Test.main(Test.java:7)
package test;
public class Test {
public static void main(String args[]) {
try {
System.out.println(12 / 0);
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
}
}