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