Complete the code to declare a custom exception class that extends RuntimeException.
public class MyException extends [1] { public MyException(String message) { super(message); } }
The custom exception class should extend RuntimeException to create an unchecked exception.
Complete the code to throw the custom exception with a message.
if (user == null) { throw new [1]("User not found"); }
Throw the custom exception MyException to indicate a specific error condition.
Fix the error in the custom exception constructor to properly pass the message to the superclass.
public class MyException extends RuntimeException { public MyException(String message) { [1](message); } }
this(message) instead of super(message).throw or return inside constructor.The constructor must call super(message) to pass the message to the RuntimeException constructor.
Fill both blanks to create a custom exception with a default message and a constructor that accepts a message.
public class [1] extends RuntimeException { public [2]() { super("Default error message"); } }
The class name and constructor name must match. Here, both are MyException.
Fill all three blanks to define a custom exception with two constructors: one default and one with a message.
public class [1] extends RuntimeException { public [2]() { super("Default message"); } public [3](String message) { super(message); } }
All constructors and the class must share the same name, here CustomException.