Eclipse中Debug和Run模式下输出顺序的差异。

时间:2014-09-30 14:45:57

标签: java eclipse exception-handling

为什么以下Java程序的输出表示在Eclipse中的Debug和Run as Java应用程序模式中有所不同?

对于以下Java代码,

public class ThrowDemo {

    static void demoproc() {
        try {
            NullPointerException nullPointerException = new NullPointerException();
            throw nullPointerException; // or new NullPointerException();
            //System.out.println("Unreachable Code is an error in Java");
        } catch (NullPointerException e) {
            System.out.println("Caught inside demoproc.");
            throw e; // rethrow the exception
        }
    }

    static void throwing(){
        throw new NullPointerException();
    }

    public static void main(String args[]) {
        try {
            demoproc();
        } catch (NullPointerException e) {
            System.out.println("Recaught: " + e);
        }
        throwing();
    }
}

当我将其作为Java应用程序调试时,输出必须按照列表顺序排列。

Caught inside demoproc.
Recaught: java.lang.NullPointerException
Exception in thread "main" java.lang.NullPointerException
    at throwkeyword.ThrowDemo.throwing(ThrowDemo.java:17)
    at throwkeyword.ThrowDemo.main(ThrowDemo.java:26) 

当我将其作为Java应用程序运行时,列表如下:

Caught inside demoproc.
Exception in thread "main" java.lang.NullPointerException
    at throwkeyword.ThrowDemo.throwing(ThrowDemo.java:17)
    at throwkeyword.ThrowDemo.main(ThrowDemo.java:26)
Recaught: java.lang.NullPointerException

为什么它(控制台)在Eclipse中有这么大的差异?

0 个答案:

没有答案