Bird
0
0

Given this custom exception class:

medium📝 component behavior Q13 of 15
Spring Boot - Exception Handling
Given this custom exception class:
public class DataNotFoundException extends RuntimeException {
  public DataNotFoundException(String message) {
    super(message);
  }
}

What will happen if this exception is thrown in a Spring Boot controller without any handler?
AThe exception will be ignored and the request will succeed
BThe application will return a 500 Internal Server Error response
CThe application will automatically return a 404 Not Found response
DThe server will crash and stop running
Step-by-Step Solution
Solution:
  1. Step 1: Understand default Spring Boot behavior

    Without a handler, Spring Boot treats RuntimeExceptions as server errors and returns HTTP 500.
  2. Step 2: Check other options

    Ignoring exceptions or auto 404 responses require explicit handling; server crash does not happen.
  3. Final Answer:

    The application will return a 500 Internal Server Error response -> Option B
  4. Quick Check:

    Unhandled RuntimeException = HTTP 500 error [OK]
Quick Trick: Unhandled RuntimeException returns HTTP 500 by default [OK]
Common Mistakes:
  • Assuming automatic 404 response
  • Thinking exceptions are ignored
  • Believing server crashes on exception

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes