Each of those executions will produce a different sort of Exception, and you can see the stack traces at the command line. They tell you where the Exception originated, and all the lines it has passed through until it was caught. If yoo delete the catch block and the keyword try, you can repeat the exercise and see whether you obtain a different stack trace.
I did not understand at all what means in this quote!
You are printing the stack trace, as well as the toString() representation of the Exception. Since you are using System out (don't use System.out for Exceptions, use System.err), you have part printed on System.out and part (the stack trace) on System.err, and you may actually have the lines from one print-out interspersed with the other.
Campbell Ritchie wrote:You are printing the stack trace, as well as the toString() representation of the Exception. Since you are using System out (don't use System.out for Exceptions, use System.err), you have part printed on System.out and part (the stack trace) on System.err, and you may actually have the lines from one print-out interspersed with the other.
Does that mean, System.err() wont give the toString() representation?!
Is there any difference at all between the 2 - System.out() and System.err()?? Both prints into the monitor,right?
They do both print to the monitor but they print in different streams which means that the values they are printing could potentially overlap. When printing out error information you should use System.err.println() like Campbell suggested, This will guarantee that your data won't overlap.
"If the facts don't fit the theory, get new facts" --Albert Einstein
Joined: Oct 13, 2005
As Hunter McMillan implies, you can get your data printed in different orders if you use System.out and System.err simultaneously in repeated executions. You do actually appear to have overlapping outputs on what you quoted.
System.out and System.err both print to the screen by default, but don't have to both print there. You can redirect them to different files.
If you do have both print to the screen, it's effectively (perhaps literally) two different threads doing the printing. So, you may get 2 lines from one, then a line from the other, then 3 more from the first, then 8 from the second, etc.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors