Java/Exception Handing
예외처리 throw사용법
Bohemian life
2012. 4. 11. 17:42
package com.basic;//예외처리 throw 사용법(예외를 강제적으로) public class ThrowEx1 { public void methodA(String[] n)throws Exception{ if(n.length>0){ //개선된 루프 (jdk5.0이상에서만 사용가능) //n은 인덱스 주소값을 모두 출력해서 s에 저장(?) for(String s : n) System.out.println(s); }else throw new Exception("배열에 요소가 없습니다1."); } public static void main(String[] args){ ThrowEx1 te = new ThrowEx1(); try{ te.methodA(args); }catch(Exception e){//11라인 출력 System.out.println(e.getMessage()); //e.printStackTrace();//부가 적으로 자세히 나옴 jsp에 많이 사용 } } }
배열에 요소가 없습니다1.