Performance: @ExceptionHandler in controllers
MEDIUM IMPACT
This affects server response time and error handling efficiency, indirectly impacting user experience by controlling error response speed and page stability.
@Controller public class MyController { @ExceptionHandler(Exception.class) public ResponseEntity<String> handleAllExceptions(Exception ex) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Custom error message"); } }
public String handleRequest() {
try {
// controller logic
} catch (Exception e) {
return "errorPage";
}
}| Pattern | Server Processing | Code Duplication | Response Consistency | Verdict |
|---|---|---|---|---|
| Try-catch in each controller method | High - repeated handling | High - duplicated code | Low - inconsistent | [X] Bad |
| Centralized @ExceptionHandler method | Low - single handler | Low - centralized code | High - consistent | [OK] Good |