2016-11-17 4 views
0

두 개의 AfterThrowing 권고를 정의하여 동일한 pointcut을 사용하는 예외를 처리했습니다.특정 예외 유형 처리

@AfterThrowing(pointcut="...", throwing="ex") 
public void method1(Exception ex) {} 


@AfterThrowing(pointcut="...", throwing="ex") 
public void method2(GatewayException ex) {} 

예외가 GatewayException 인 경우 일반 method1이 실행되는 것을 방지 할 수있는 방법이 있습니까?

어떤 아이디어가 크게

감사

C는 조언 본체 내부의 예외의 인스턴스를 확인하고보다 구체적인 예외 유형의 경우 조기 반환하는 가장 쉬운 것

답변

0

:

@AfterThrowing(pointcut="...", throwing="ex") 
public void method1(Exception ex) { 
    if (ex instanceof GatewayException) { 
     return; 
    } 
    // handle the more generic Exception case 
} 


@AfterThrowing(pointcut="...", throwing="ex") 
public void method2(GatewayException ex) { 
    // handle the more specific GatewayException 
} 

AspectJ 언어 구조를 기반으로 한 솔루션을 기대했지만, 그런 구조는 없다는 것을 알고 있습니다.

+0

그래, 나는 instanceof를 피하기를 바랬지 만 당신이 옳다고 생각합니다. – Cathal