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());
}
source
share