public class NotGirlFriendException extends Exception {
public NotGirlFriendException() {
}
public NotGirlFriendException(String message) {
super(message);
}
}
public class GirlFriend {
String name;
int age;
public GirlFriend(String name, int age) throws NotGirlFriendException {
this();
this.name = name;
this.age = age;
}
public GirlFriend() throws NotGirlFriendException {
throw new NotGirlFriendException("you are not girlfriend");
}
}
public class Test {
public static void main(String[] args) {
try {
GirlFriend girlFriend=new GirlFriend();
}catch (NotGirlFriendException e){
System.out.println(e.getMessage());
}
}
}
output
you are not girlfriend