如下图,如果在catch语句中把e.printStackTrace放在第一句,异常的输出也是在第一句,和我们想法一样
but 如果将e.printStackTrace放在第二句,在输出面板上的异常输出并不是我们想要的在第二句执行,而是在最后一句输出(但此时如果以debug的形式进行测试,异常输出是在第二位的),如下图:
这是因为我们正常使用 printStackTrace()的时候默认是输出到System.err中去的,而普通的输出都是放入System.out,这两者都是对上层封装的输出流,在默认情况下两者是指向Console的文本流。所以两者可能会出现同步问题。
解决办法是在e.printStackTrace()以System.out的形式输出,如下图,顺序正常了