Custom Exception Program ?

 package ExceptionHandling;


public class CustomExceptionExample extends Exception {


CustomExceptionExample() {

super("invalid age");

}


CustomExceptionExample(String str) {

super(str);

}


static int age = 15;


public static void main(String[] args) {

try {

if (age < 10) {

throw new CustomExceptionExample("Invlid age");

} else {

System.out.println("valid age");

}

} catch (CustomExceptionExample e) {

// TODO Auto-generated catch block

System.out.println(e.getMessage());

}

}

}

Comments

Popular posts from this blog

Hello World Program In Flutter using Android Studio.

what is Angular Architecture ?

Java Notes