Search This Blog

Tuesday, 16 September 2014

JAVA EXCEPTION - IllegalArgumentException

Java Exception -> IllegalArgumentException

IllegalArgumentException is a Runtime Exception.

Class Hierarchy is as follows: 

 IllegalArgumentException thrown to indicate that a method has been passed an Illegal Argument.


public class Voters {

 String voter_name;
 int voter_age;

//u can throw this exception like this
//rule: age should be > 18 years

 private void checkAge(int voter_age){
      throw new IllegalArgumentException();
 public Voters(String voterName,
                 String voterAge) {


  Like this you can throw this exception.

No comments:

Post a Comment