I have the following lines of code, and I'm supposed to write an IllegalArgumentException exception, such that when I run it ,it returns "Poland already exists.". I've been reading on exceptions a lot but I just can't figure out how I am supposed to write the IllegalArgumentException, what to put in its constructor, etc (I just know I must have a constructor and a getMessage() method for the message.)
More specifically: how do I change the "cause" for the IllegalArgumentException: how do I make it check for the similarity in name of the countries?
public static void main(String[] args) {
Country country1 = new Country("Poland");
try{
Country country = new Country("Poland");
}
catch(IllegalArgumentException ie){
System.out.println(ie.getMessage());
}
}