Is there any priority between multiple try / catch attempts in java?

In the program below, sometimes I get the following output:

Number Format Execption For input string: "abc"
123

and sometimes:

123
Number Format Execption For input string: "abc"

Is there any priority between try / catch block or priority between System.out and System.err?

What is the reason for random output?

the code:

String str1 = "abc";
String str2 = "123";

     try{
         int firstInteger = Integer.parseInt(str1);
         System.out.println(firstInteger);
     }
     catch(NumberFormatException e){
         System.err.println("Number Format Execption " + e.getMessage());
     }

       try{
         int SecondInteger = Integer.parseInt(str2);
         System.out.println(SecondInteger);
         }
     catch(NumberFormatException e){
         System.err.println("Number Format Execption " + e.getMessage());
     }
+3
source share
2 answers

This has nothing to do with try / catch and everything you do to write to System.out and System.err; they are two different streams, and you cannot control the order of their rotation, since they are written to the console.

+12
source

Try to clear the threads explicitly,

System.out.flush();
System.err.flush();
0
source