Spring MVC Best Practices Handling Fatal Exceptions in a Controller

When you have a controller that runs logic with services and DAOs that can throw an unrecoverable exception, what is the best practice regarding these method calls?

Currently the application I'm working on has very long try catch methods that simply eliminate error messages. This doesn't seem very reliable, and I think this code smells, is there any culinary cutting program to handle this in spring -mvc?

+3
source share
2 answers

Take a look at @ExceptionHandler

You can use it as

@ExceptionHandler(IOException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public void handleExc(IOException ext) {}

IOExceptions, , 500 .

+6

HandlerExceptionResolver.

SimpleMappingExceptionResolver Context ( ) (, errorpage "). , , .

, , , , ", - , , " stacktrace.

+8

Source: https://habr.com/ru/post/1738963/


All Articles