很奇妙啊。
package t055;public class Threads2 implements Runnable { public void run() {
System.out.println("run.");
throw new RuntimeException("Problem");
} public static void main(String[] args) { Thread t = new Thread(new Threads2());
t.start();
System.out.println("End of method.");
}
}
打印结果必然显示run,problem,end of method这三个字符串,而且任意一种顺序都有可能。可能的有:End of method.
run.
Exception in thread "Thread-0" java.lang.RuntimeException: Problem
at t055.Threads2.run(Threads2.java:7)
at java.lang.Thread.run(Thread.java:619)
Exception in thread "Thread-0" End of method.
run.
java.lang.RuntimeException: Problem
at t055.Threads2.run(Threads2.java:7)
at java.lang.Thread.run(Thread.java:619)
End of method.Exception in thread "Thread-0" java.lang.RuntimeException: Problem
at t055.Threads2.run(Threads2.java:7)
at java.lang.Thread.run(Thread.java:619)run.
Exception in thread "Thread-0" java.lang.RuntimeException: Problem
at t055.Threads2.run(Threads2.java:7)
at java.lang.Thread.run(Thread.java:619)
End of method.
run.我真是奇了怪了,run居然有可能在处理异常之后输出,这是怎么回事,谁能解释一下。
package t055;public class Threads2 implements Runnable { public void run() {
System.out.println("run.");
throw new RuntimeException("Problem");
} public static void main(String[] args) { Thread t = new Thread(new Threads2());
t.start();
System.out.println("End of method.");
}
}
打印结果必然显示run,problem,end of method这三个字符串,而且任意一种顺序都有可能。可能的有:End of method.
run.
Exception in thread "Thread-0" java.lang.RuntimeException: Problem
at t055.Threads2.run(Threads2.java:7)
at java.lang.Thread.run(Thread.java:619)
Exception in thread "Thread-0" End of method.
run.
java.lang.RuntimeException: Problem
at t055.Threads2.run(Threads2.java:7)
at java.lang.Thread.run(Thread.java:619)
End of method.Exception in thread "Thread-0" java.lang.RuntimeException: Problem
at t055.Threads2.run(Threads2.java:7)
at java.lang.Thread.run(Thread.java:619)run.
Exception in thread "Thread-0" java.lang.RuntimeException: Problem
at t055.Threads2.run(Threads2.java:7)
at java.lang.Thread.run(Thread.java:619)
End of method.
run.我真是奇了怪了,run居然有可能在处理异常之后输出,这是怎么回事,谁能解释一下。
if (2>1){
throw new RuntimeException("Problem");
}
System.out.println("run.");