Custom exceptions are used to handle specific error cases in your application.
Source Code
class MyException extends Exception {
public MyException(String message) {
super(message);
}
}
public class Test {
public static void main(String[] args) {
try {
throw new MyException("Custom Exception Message");
} catch (MyException e) {
System.out.println(e.getMessage());
}
}
}