spring로 검색한 결과 :: 시소커뮤니티[SSISO Community]
 
SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기   우측부분

회원가입 I 비밀번호 찾기


SSISO Community검색
SSISO Community메뉴
[카페목록보기]
[블로그등록하기]  
[블로그리스트]  
SSISO Community카페
블로그 카테고리
정치 경제
문화 칼럼
비디오게임 스포츠
핫이슈 TV
포토 온라인게임
PC게임 에뮬게임
라이프 사람들
유머 만화애니
방송 1
1 1
1 1
1 1
1 1
1

spring로 검색한 결과
등록일:2008-06-10 17:19:57
작성자:
제목:AOP 예제4 - Throws Advice


package com.youngkun.aoptest;

public class ErrorBean {
   public void errorProneMethod() throws Exception{
       throw new Exception("Foo");
   }
  
   public void otherErrorProneMethod() throws IllegalArgumentException{
       throw new IllegalArgumentException("Bar");
   }
}

package com.youngkun.aoptest;

import java.lang.reflect.Method;

import org.springframework.aop.ThrowsAdvice;
import org.springframework.aop.framework.ProxyFactory;

public class SimpleThrowsAdvice implements ThrowsAdvice{
  
   public static void main(String[] args) {
       ErrorBean errorBean = new ErrorBean();
      
       ProxyFactory pf = new ProxyFactory();
       pf.setTarget(errorBean);
       pf.addAdvice(new SimpleThrowsAdvice());
      
       ErrorBean proxy = (ErrorBean)pf.getProxy();
      
       try{
           proxy.errorProneMethod();
       }catch(Exception ignored){}
      
       try{
           proxy.otherErrorProneMethod();
       }catch(Exception ignored){}
   }
  
   public void afterThrowing(Exception ex) throws Throwable{
       System.out.println("***");
       System.out.println("Generic Exception Capture");
       System.out.println("Caught: " + ex.getClass().getName());
       System.out.println("***\n");
   }
  
   public void afterThrowing(Method method, Object[] args, Object target, IllegalArgumentException ex)
       throws Throwable{
       System.out.println("***");
       System.out.println("IllegalArgumentException Capture");
       System.out.println("Caught: "+ ex.getClass().getName());
       System.out.println("Method: "+ method.getName());
       System.out.println("***\n");
   }
}


실행 결과

***
Generic Exception Capture
Caught: java.lang.Exception
***

***
IllegalArgumentException Capture
Caught: java.lang.IllegalArgumentException
Method: otherErrorProneMethod
***

 

출처 : http://youngkun.info/95