Top Exception Handling Interview Questions Every Senior Backend Engineer Should Know
Top Exception Handling Interview Questions Every Senior Backend Engineer Should Know Work through these 12 questions out loud. Open any question for the full model answer, the trap to avoid, and the follow-up a panel usually asks.
What are common mistakes freshers make in Spring Boot projects?
```java // ❌ Wrong @RestController public class OrderController { @PostMapping("/orders") public Order create(@RequestBody Order o) { return orderRepository.save(o); // DB in...
Explain the difference between == and .equals() in Java.
For primitives, == compares values. For objects, == asks if two references point to the same instance. equals() compares content when overridden — String overrides it for...
What happens if @Transactional fails midway? How do you verify rollback?
Default: runtime exception marks rollback-only; transaction commits nothing on exit. ```java @Transactional(rollbackFor = Exception.class) public void placeOrder(Order o) {...
What happens if an exception occurs inside a filter or interceptor?
Exceptions in `Filter` bypass `@ControllerAdvice` unless handled. Filters run before MVC. ```java @Override protected void doFilterInternal(HttpServletRequest req,...
How do you handle exceptions globally in Spring?
Create @RestControllerAdvice with @ExceptionHandler(MethodArgumentNotValidException.class) returning 400 + field map, NotFoundException → 404, generic Exception → 500 without...
What is Optional and when should you use it?
Use Optional as return type when absence is expected — findById returns Optional<User>. Chain with map/flatMap/orElseThrow. Do not use for fields, method parameters, or Jackson...
When should you use CopyOnWriteArrayList?
Use for subscriber lists in pub/sub where adds are rare and iteration is constant. Avoid for high-frequency add/remove — use ConcurrentLinkedQueue or synchronized collections....
Multiple beans of the same type exist and Spring throws an error. How do you fix it?
Spring needs disambiguation when two `@Service` implement the same interface. ```java @Primary @Service public class StripePaymentGateway implements PaymentGateway {} @Service...
Difference between @Component, @Service, @Repository?
All register as singleton beans via component scan. Choose by layer for readability: @Repository on DAOs (plus SQLException translation), @Service on business logic, @Component...
Explain try-with-resources and suppressed exceptions.
try (Connection c = ds.getConnection(); PreparedStatement ps = c.prepareStatement(sql)) { ... } — both closed even on SQLException. Check e.getSuppressed() in logs for close...
How does Bean Validation work in Spring Boot 3?
DTO fields: @NotBlank, @Email, @Size. Controller: createUser(@Valid @RequestBody UserDto dto). Global @RestControllerAdvice maps MethodArgumentNotValidException to 400 + field...
What is ProblemDetail (RFC 7807) in Spring 6 error handling?
@ExceptionHandler(NotFoundException.class) ProblemDetail handle(NotFoundException ex) { return ProblemDetail.forStatusAndDetail(NOT_FOUND, ex.getMessage()); } — consistent 404...
Exception Handling Interview Questions and Answers · Top 50 Exception Handling Interview Questions and Answers (2026 Edition) · Top 40 Exception Handling Interview Questions | Must-Prepare before interview. · Exception Handling Interview Questions Every Fresher Must Know
All interview question lists · Interview guides · Home · Support the platform