Bird
0
0

Why is it recommended to extend RuntimeException instead of Exception when creating custom exceptions in Spring Boot?

hard📝 Conceptual Q10 of 15
Spring Boot - Exception Handling
Why is it recommended to extend RuntimeException instead of Exception when creating custom exceptions in Spring Boot?
ABecause Exception classes are deprecated in Spring Boot
BBecause RuntimeExceptions are unchecked and do not require explicit try-catch blocks
CBecause RuntimeException automatically logs errors
DBecause Exception classes cannot have constructors
Step-by-Step Solution
Solution:
  1. Step 1: Understand checked vs unchecked exceptions

    Exception is checked, requiring try-catch or throws declaration; RuntimeException is unchecked.
  2. Step 2: Reason why RuntimeException is preferred

    Unchecked exceptions simplify code by not forcing explicit handling, making custom exceptions easier to use.
  3. Final Answer:

    Because RuntimeExceptions are unchecked and do not require explicit try-catch blocks -> Option B
  4. Quick Check:

    Unchecked exceptions avoid mandatory try-catch [OK]
Quick Trick: Unchecked exceptions simplify code by avoiding forced try-catch [OK]
Common Mistakes:
  • Believing Exception classes cannot have constructors
  • Thinking RuntimeException logs errors automatically
  • Assuming Exception classes are deprecated

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes