throw an exception from catch block and user defined Exception class in java code example
Example: java define custom exception
public class CustomException extends Exception {
public CustomException(String errorMessage) {
super(errorMessage);
}
}