I was experimenting something with exceptions in java and during execution found something strange. The following is the code I was trying with,
public class Client
{
@SuppressWarnings("finally")
public static void main(String a[])
{
try {
throw new IllegalArgumentException("First Exception");
} catch (Exception e) {
System.out.println("SOP 1 ");
throw new IllegalArgumentException("Second Exception");
} finally {
System.out.println("SOP 2");
throw new IllegalArgumentException("Thried Exception");
}
}
}
I was getting the following jumbled output in each execution (though mostly I was getting the Result 1, which is the expected o/p according to me). I was using Eclipse IDE for the execution. Couldn't find a reason for this, can someone pls clarify why the output is coming jumbled like this ?
(Result 1)---------------------------------------------------------------------
SOP 1
SOP 2
Exception in thread "main" java.lang.IllegalArgumentException: Thried Exception
at client.main(client.java:13)
(Result 2)---------------------------------------------------------------------
Exception in thread "main" java.lang.IllegalArgumentException: Thried Exception
at client.main(client.java:13)
SOP 1
SOP 2
(Result 3)---------------------------------------------------------------------
Exception in thread "main" SOP 1
SOP 2
java.lang.IllegalArgumentException: Thried Exception
at client.main(client.java:13)
-------------------------------------------------------------------------------