throw an exception with message java code example
Example 1: java how to throw exception
public class ThrowException{
public static void main(String [] args) throws Exception{
throw new Exception("Errmessage");
}
}
Example 2: throwing exceptions java
public class ThrowExample {
static void checkEligibilty(int stuage, int stuweight){
if(stuage<12 && stuweight<40) {
throw new ArithmeticException("Student is not eligible for registration");
}
else {
System.out.println("Student Entry is Valid!!");
}
}
public static void main(String args[]){
System.out.println("Welcome to the Registration process!!");
checkEligibilty(10, 39);
System.out.println("Have a nice day..");
}
}