public class ExceptionTest{
	static public void main(String arg[]){
		int data[]={-1,0,1};
		for(int i=0;i<data.length;i++){
			try{
				test(data[i]);//例外を発生する関数を呼ぶ	
				
			//例外とエラーを分けて捕まえる事が可能	
			}catch(Exception e){
				System.err.println("例外処理");
				e.printStackTrace();
			}catch(Error e){
				System.err.println("エラー処理");
				e.printStackTrace();
				//エラーを捕まえるとも可能
			}
		}
		System.err.println("\n mainを終了します \n");
	}
	
	static void test(int data) throws Exception//投げる例外を明記
	{
		if(0<=data)test2(data);
		else throw new Exception("DATAが負");
	}
	
	static void test2(int data) throws Exception//Errorはthrowsに書く必要がない
	{
		if(data==0)throw new Exception("DATAが0");
		throw new Error("DATAが正");//例外の他にエラーも投げることが可能
	}
	
}