Error handlingsenior8+ years
What does Spring Boot do by default when a controller throws an uncaught exception, and how would you replace it with your own error contract?
Out of the box, Boot's BasicErrorController (backed by DefaultErrorAttributes) turns any uncaught exception into a generic JSON body — timestamp, status, error, path, and, if enabled, message/trace — mapped to /error and rendered with a status derived from the exception (a ResponseStatusException or an @ResponseStatus-annotated exception maps directly; everything else defaults to 500). That default shape is rarely what a real API wants to expose: for a production service you replace or extend it with a @RestControllerAdvice and @ExceptionHandler methods, or implement ErrorAttributes yourself, so the error contract is intentional and consistent rather than whatever the default happened to produce — and so internal details never leak.