一个类的异常处理

时间:2015-12-11 20:01:18

标签: java spring

有没有办法处理方法中某个特定类的异常?

我不知道在application-context.xml中使用Spring

这样的事情:

<textarea>

而不是在所有方法中使用多个try catch块。

1 个答案:

答案 0 :(得分:0)

这是@ExceptionHandler注释的用途。

@ExceptionHandler(SomeException.class)
public void handleSomeException(SomeException e) {
    // Log the exception or whatever
}

如果在同一个类中发生异常,则需要调用它,该类需要是Spring组件。