| Author |
Getting a different output everytime a catch block is executed.
|
Chan Ag
Ranch Hand
Joined: Sep 06, 2012
Posts: 39
|
|
Hi,
Sorry in advance if this is a stupid question.
Could somebody please explain why the order of lines in the output varies everytime I execute the following program.
I have received three different output cases. They are as follows.
run:
java.lang.Exception: Exception Again
hello
Not Terminated yet
at TestSimple.ExceptionTest2.workonExceptions(ExceptionTest2.java:25)
at TestSimple.ExceptionTest2.main(ExceptionTest2.java:14)
BUILD SUCCESSFUL (total time: 0 seconds)
run:
hello
java.lang.Exception: Exception Again
Not Terminated yet
at TestSimple.ExceptionTest2.workonExceptions(ExceptionTest2.java:25)
at TestSimple.ExceptionTest2.main(ExceptionTest2.java:14)
BUILD SUCCESSFUL (total time: 0 seconds)
run:
hello
Not Terminated yet
java.lang.Exception: Exception Again
at TestSimple.ExceptionTest2.workonExceptions(ExceptionTest2.java:25)
at TestSimple.ExceptionTest2.main(ExceptionTest2.java:14)
BUILD SUCCESSFUL (total time: 0 seconds)
I just don't see why stackprinttrace should start before hello is printed. Also in the third run, even 'Not Terminated yet' is printed before stacktrace has started. I can't understand this behaviour. Is this related to threads? Does printstacktrace run as a separate thread or something? Could somebody please advice.
Thanks.
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 5793
|
|
The stack traces are going to System.err, but your println()s are going to System.out. Those two Streams (Writers?) can dump their bytes out to the console independently of each other, without regard to the order in which they were filled up.
WIthin a given stream--out or err--the messages will be in order, but between the two, they can be interleaved.
|
 |
Chan Ag
Ranch Hand
Joined: Sep 06, 2012
Posts: 39
|
|
|
Thanks, Jeff.
|
 |
 |
|
|
subject: Getting a different output everytime a catch block is executed.
|
|
|