運行時異常

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章