class InvalidAgeException extends Exception{
InvalidAgeException(String s){
super(s);
}
public String toString()
{
return "Candidate is less than 18 year is not allowed to vote.";
}
}
class ValidateCandidate{
static void validate(int age) throws InvalidAgeException{
if(age < 18)
throw new InvalidAgeException("invalid candidate");
else
System.out.println("welcome to vote");
}
public static void main(String args[]){
try{
validate(13);
}catch(Exception ex){
System.out.println("Exception occured: "+ex);
}
System.out.println("rest of the code...");
}
}
output here:
Points to Remember
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…