Java - Custom Exceptions
You want to create a custom unchecked exception named
InvalidDataException. Which is the correct way to define it?InvalidDataException. Which is the correct way to define it?RuntimeException, checked exceptions extend Exception.RuntimeException with proper constructor. public class InvalidDataException extends Exception {
public InvalidDataException(String message) {
super(message);
}
} creates a checked exception. public class InvalidDataException implements RuntimeException {
public InvalidDataException(String message) {
super(message);
}
} tries to implement an exception class, which is invalid. public class InvalidDataException extends Throwable {
public InvalidDataException(String message) {
super(message);
}
} extends Throwable directly, which is not recommended for custom exceptions.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions