@ControllerAdvicepublic class GlobalExceptionHandler { @ExceptionHandler(NullPointerException.class) public ResponseEntity handleNullPointer(NullPointerException ex) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Null value encountered."); }}
@ControllerAdvicepublic class GlobalExceptionHandler { @ExceptionHandler(Exception.class) public ResponseEntity handleAllExceptions(Exception ex) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ex.getMessage()); }}
@Controllerpublic class GlobalExceptionHandler { @ExceptionHandler(Exception.class) public ResponseEntity handleExceptions(Exception ex) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error: " + ex.getMessage()); }}
@RestControllerAdvicepublic class GlobalExceptionHandler { @ExceptionHandler(RuntimeException.class) public ResponseEntity handleRuntimeException(RuntimeException ex) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("A runtime error occurred."); }}