0

Can somebody please explain me the difference between the following cases? In both cases we see an Exception on the console, but they are presented in a different way.enter image description here

and

enter image description here

ArminB
  • 35
  • 1
  • 8
  • 3
    I believe that Eclipse displays stderr in red and stdout in black. – Oliver Charlesworth Mar 24 '18 at 12:31
  • 2
    Confirming the info of @OliverCharlesworth could be as simple as `System.err.println("Error"); System.out.println("Out");` – Andrew Thompson Mar 24 '18 at 12:37
  • Printing stacktrace liike `e.printStackTrace()` comes in red, routing it through a custom exception using a `log4j` like logging framework and configuring `stdout` as an appender can make it black too – absin Mar 26 '18 at 14:58

1 Answers1

0

There are two ways to send output to the console (here Eclipse console, but anywhere you run your Java program). One using "System.out" and one using "System.err".

Try writing a small program like

....
System.out.println("System.out");
System.err.println("System.err");
....

and run it. You should see that their colors are different.

So it is just where the code printing the stack trace choose to send it to.

If you run it directly from the command line, there is typically no additional treatment and the two will look the same.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347