Throw catch Exception

This Exception used when we want to throw user-defined exception.


public class birthday{
private int birhMonth;
public birhday(int month) {
if(month<=12&&month>0)
 this.birthMonth=month;
  else
  {
    throw new IllegalArgumentException("Insert Valid month");
  }
}
}

When an Exception caught the Stub will show the "Insert valid month " messege;

0 comments:

Post a Comment

My Instagram