Difference between e.printStackTrace and System.out.println(e)

The output stream used is not the same as pointed out by @Brian, but the level of detail is not the same either – you can try with the simple test below. Output:

With println: you only know what exception has been thrown

java.lang.UnsupportedOperationException: Not yet implemented

With printStackTrace: you also know what caused it (line numbers + call stack)

java.lang.UnsupportedOperationException: Not yet implemented
at javaapplication27.Test1.test(Test1.java:27)
at javaapplication27.Test1.main(Test1.java:19)

public static void main(String[] args){
    try {
        test();
    } catch (UnsupportedOperationException e) {
        System.out.println(e);
        e.printStackTrace();
    }
}

private static void test() {
    throw new UnsupportedOperationException("Not yet implemented");
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)