With this code:
class SimpleException extends Exception {}
public class SimpleExceptionDemo {
public void f() throws SimpleException {
System.out.println("Throw SimpleException from f()");
throw new SimpleException();
}
public static void main(String[] args) {
SimpleExceptionDemo sed = new SimpleExceptionDemo();
try {
sed.f();
} catch(SimpleException e) {
System.err.println("Caught it!");
}
}
}
In some case i have this output:
Caught it!
Throw SimpleException from f()
Do you know why "Throw SimpleException from f()" is printed after "caught it"?
You are printing on two different output streams:
System.out.println("Throw SimpleException from f()");
and
System.err.println("Caught it!");
The order of the messages appearing from the two different streams is not guaranteed... Use the same stream, and it will be OK.
If you're interested in such issues, it might be interesting to read up on
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With