• Post Reply Bookmark Topic Watch Topic
  • New Topic

printStackTrace clarification  RSS feed

 
Karl Prenton
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably a silly question, but I can't find where in JLS/javadocs it says that standard error stream is asynchronous. I only ask this after realizing that dumping the stack trace does not appear immediately e.g.

public class TestPrintStackTrace {

public static void main(String... args)
{
try
{
throw new Exception("deliberate");
}
catch(Exception e)
{
e.printStackTrace();
}
for( int k=0; k<=10;k++)
{
System.out.println("k==" + k);
}
}
}

Stack trace is printed after the loop is printed.

Is it that printStackTrace is standard error output stream whereas the println goes to the standard output stream - which I assume, is handled by a separate thread?
 
Karl Prenton
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to prove to myself that each output stream is handled I can redirect the println (standard) to the printStrackTrace (error) output stream to make the output appear in the order it was exectuted :

System.setOut(System.err);

But I never see references to "asynchronous" or "separate thread" in places where it talks about streams?!? e.g http://en.wikipedia.org/wiki/Standard_input
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know about the asynchronicity, but yes, printStackTrace() defaults to standard error, and the two output streams obviously do print out at different times.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!