Console Printing Order in Eclipse [duplicate]

本秂侑毒 提交于 2019-11-27 09:45:33
cxw

A bit more detail: the output from your print statements is going to System.out. However, the exception messages are going to System.err (see this). These two are separate output streams that both happen to go to the same place: your console. They are buffered and processed independently. In the second situation you show, the print statements are buffering up but not yet printed when the exception happens.

edit There is an added complication here, which is that the Eclipse console is not a real Windows console. As noted here among other places, there have in the past been problems with the Eclipse console on Windows platforms because Windows does not give Eclipse a good way to make its console behave just like a native console. If you add flush calls and still have problems, try running your program from a command prompt and see if that makes a difference.

Two different streams are being used here. You are using System.out. and the exception is printed with System.err. They are buffered, so one's output may print before the other's.

You can call System.out.flush(); before the exception line:

System.out.flush();
c = a/b;  //Arthmetic Exception
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!