Bird
0
0

Consider this custom exception class:

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

What will be the output if this exception is thrown with message "User missing" and caught to print getMessage()?
Anull
BUser missing
CUserNotFoundException
DException occurred
Step-by-Step Solution
Solution:
  1. Step 1: Understand constructor usage

    The constructor passes the message to RuntimeException's constructor.
  2. Step 2: Check getMessage() behavior

    getMessage() returns the message passed to the exception, here "User missing".
  3. Final Answer:

    User missing -> Option B
  4. Quick Check:

    getMessage() returns passed message [OK]
Quick Trick: getMessage() returns the message passed to exception constructor [OK]
Common Mistakes:
  • Expecting class name instead of message
  • Assuming null if message is passed
  • Confusing getMessage() with toString()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes