Annotation Interface CallableExceptionHandler
Annotated methods are called when
@Callable
methods raise exceptions.
@Controller
class MyController {
@Callable
void foo(){
throw new RuntimeException();
}
@CallableExceptionHandler
void exceptionHandler(Exception e) {
// Called when callable methods raise exceptions
}
}
If the value() is set to other than AbstractTypedMethods.TYPE_ALL,
the methods are called only when exceptions are thrown by the specified callable methods.
@Controller
class MyController {
@Callable
void foo(){
throw new RuntimeException();
}
@Callable
void bar(){
throw new RuntimeException();
}
@CallableExceptionHandler("foo")
void exceptionHandler(Exception e) {
// This method will be called when the callable method "foo" raises exceptions.
// But won't be called when the callable method "bar" raises exceptions.
}
}
If the thrown exceptions are not assignable to the argument of annotated methods,
methods are not called.
@Controller
class MyController {
@Callable
void foo(){
throw new RuntimeException();
}
@CallableExceptionHandler
void exceptionHandler(IlligalStateException e) {
// This method will not be called since RuntimeException is not assignable to IllegalStateException.
}
}
If there are more than one excepton handlers, the method with strictest argument type will be called.
@Controller
class MyController {
@Callable
void foo(){
throw new RuntimeException();
}
@CallableExceptionHandler
void exceptionHandler1(Exception e) {
// This method will not be called since exceptionHandler2 has the more strict argument type.
}
@CallableExceptionHandler
void exceptionHandler2(RuntimeException e) {
// This method will be called since RuntimeException is more strict compared to Exception.
}
}
The argument can be omitted if thrown exceptions themselve aren't required.
@Controller
class MyController {
@Callable
void foo(){
throw new RuntimeException();
}
@CallableExceptionHandler
void exceptionHandler1() {}
}- 関連項目:
-
任意要素の概要
任意要素
-
要素の詳細
-
value
String[] value- デフォルト:
- {"*"}
-