【发布时间】:2013-05-27 18:55:29
【问题描述】:
我有两个使用 AspectJ 编译时间编织的不同注释,比如说
1) 用于重试——如果抛出特定异常,该方法将自行重试
2) 翻译异常——即如果抛出特定异常,则会将该源异常转换为指定的目标异常
如何定义这两个注释的工作顺序。两个注解都是使用 aspectj 实现的,并使用 @around 通知。
我怎样才能实现这种类型的功能 `
Case 1
@retry(IllegalArgumentException.class)
@translate(source = IllegalArgumentException , target = IllegalStateException)
void method() {
//if it throws IllegalArgument exception
//method should retry and translate it to IllegalState after it
}
case2
@translate(source = IllegalArgumentException , target = IllegalStateException)
@retry(IllegalStateException.class)
void method() {
//methodthrows IllegalArgument exception which gets translated to IllegalState
//method should retry for IllegalStateException after it
}
`
有没有办法保证注解的操作顺序。
现在当我运行代码时,重试注释首先运行,然后异常翻译注释起作用。
【问题讨论】:
标签: java exception-handling annotations aspectj