每次执行都有异常和混乱的输出,有人可以澄清一下吗?

时间:2015-03-23 15:54:01

标签: java multithreading exception execution

我在java中尝试了一些异常,在执行过程中发现了一些奇怪的东西。以下是我尝试的代码,

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");
        }
    }
}

我在每次执行中都得到了以下混乱的输出(尽管我得到的结果是1,这是我所期望的o / p)。我正在使用Eclipse IDE执行。无法找到理由,有人可以澄清为什么输出会像这样混乱吗?

(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)

-------------------------------------------------------------------------------

0 个答案:

没有答案