Spring @ExceptionHandler handling multiple kinds of exceptions

后端 未结 3 1247
暖寄归人
暖寄归人 2021-02-03 22:18

I can\'t figure out how to handle more than one kind of exception by @ExceptionHandler.

I need to programmatically deal with these exceptions, for this I\'d need a shar

3条回答
  •  孤城傲影
    2021-02-03 22:44

    Your question is rather confusing but your exception handler method will only handle one exception at a time. It will not catch multiple exceptions and then pass both of them into your handleFormException() method. If you need to handle these exception types differently then you should create an exception handler method for each one, specify an argument of that specific Exception type to your method, and then do the appropriate handling. For example:

    @ExceptionHandler(DescriptionCstOrderException.class)
    public String handleDescriptionCstOrderException(DescriptionCstOrderException exception, ActionRequest actionRequest) {...}
    
    
    @ExceptionHandler(SpecializationCstOrderException.class)
    public String handleSpecializationCstOrderException(SpecializationCstOrderException exception, ActionRequest actionRequest) {...}
    
    // and so on...
    

    Please refer to the Spring documentation for further information:

    http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-ann-exceptionhandler

提交回复
热议问题