java运行时异常如果不捕获,异常抛出后,虚拟机会最终捕获异常,线程结束
java运行时异常可以捕获,从而让程序继续运行,
public class RunTimeExceptiontest {
public RunTimeExceptiontest() {
super();
}
public RunTimeExceptiontest(String name) throws Exception {
super();
this.str = name;
throw new Exception("112233");
}
public String str = "";
private int[] ints = new int[100];
public void testints(){
try {
ints[101] = 1000;
} catch (Exception e) {
e.printStackTrace();
}
System.out.print(100);
}
public static void main(String[] args) {
RunTimeExceptiontest r = null;
try {
r = new RunTimeExceptiontest("1123");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
r.testints();
System.out.println(r.str);
}
public void tt(){
SecurityManager sm = System.getSecurityManager();
System.setSecurityManager(sm);
}
}
6346

被折叠的 条评论
为什么被折叠?



