SCJP:程序在未捕获的异常后不会终止 [英] SCJP: Program not terminating after uncaught exception
本文介绍了SCJP:程序在未捕获的异常后不会终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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.
//exception
但是它将输出显示为
run
exception
end of method
(或)
run
end of method
exception
我想知道,一旦发生异常,程序将终止,对吗?
I wonder, once the exception has occurred the program will terminate, right?
推荐答案
不,您的程序不会终止,但是线程会终止.
No, your program does not terminate, but the thread does.
当线程引发未捕获的异常时,它将终止.您的main
线程继续运行.
When a thread throws an uncaught exception it terminates. Your main
thread continues running.
这篇关于SCJP:程序在未捕获的异常后不会终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文