本文介绍了e.printStackTrace和System.out.println(e)之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 可能是一个新手问题,但是每个人似乎都使用 e.printStackTrace(),但是我一直使用 System.out.println(e )当异常处理。有什么区别,为什么 e.printStackTrace()优先?Probably a newbie question, but everyone seems to use e.printStackTrace(), but I have always used System.out.println(e) when exception handling. What is the difference and why is e.printStackTrace() preferable?推荐答案 p>所使用的输出流与@Brian指出的不一样,但细节级别也不尽相同,您可以尝试下面的简单测试。输出: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:使用println:您只知道抛出什么异常With println: you only know what exception has been thrown使用printStackTrace:您也知道导致了什么(行号+调用堆栈) p>With printStackTrace: you also know what caused it (line numbers + call stack)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");} 这篇关于e.printStackTrace和System.out.println(e)之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 05:00
查看更多