Bird
0
0

Identify the error in this custom exception class:

medium📝 Debug Q14 of 15
Java - Custom Exceptions
Identify the error in this custom exception class:
public class MyException extends Exception {
  public MyException(String message) {
    super();
  }
}
AClass should extend RuntimeException instead
BMissing call to super(message) in constructor
CConstructor should not have parameters
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check constructor call to superclass

    The constructor takes a message but calls super() without passing it, so the message is lost.
  2. Step 2: Correct usage of super constructor

    It should call super(message) to pass the error message to the Exception class.
  3. Final Answer:

    Missing call to super(message) in constructor -> Option B
  4. Quick Check:

    Pass message to super constructor [OK]
Quick Trick: Pass message to super() in constructor [OK]
Common Mistakes:
  • Calling super() without message
  • Changing exception type unnecessarily
  • Removing constructor parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes