What is a user defined exception?
At times, depending on the need of a program, a programmer might need to create his own set of exceptions. These exceptions are called as the User defined Exceptions.
The user defined exception class should extend from Exception class.
You may override the toString() method in order to display a user friendly message.Example:
public class BloodGroupException extends Exception
private String gp;
public BloodGroupException (String gp)
this.gp = gp;
public String toString()
return "This is an incorrect Blood Group” ;