Exception is of two types :

I.) Checked Exception
II.) Unchecked Exception

Custom Exception can also be checked or unchecked exceptions type. If you want to create a Checked custom Exception, then you need to extend Checked Exception class as superclass and If you want to create a Unchecked custom Exception, then you need to extend Unchecked Exception class as superclass.

How to Create Custom Checked Exception Class:

Custom Checked Exception can be created in the following steps:

I.) Create a class and extend a checked exception class as super class
II.) Create different contructors of custom checked exception class and pass arguments in the super class constructor.
III.) throw custom checked exception in the class.

you can see in the below code that it forces either to throws at method level or catch that exception. Otherwise the code won’t compile.
Exception class is an example of checked exception.

package com.masterjavatutorial;
public class CheckedCustomException extends Exception{

	private static final long serialVersionUID = 1L; 
	
	public CheckedCustomException(){
		super();
	}
	
	public CheckedCustomException(String message){
		super(message);
	}

	public CheckedCustomException(Throwable th){
		super(th);
	}
	
	public CheckedCustomException(String message,Throwable th){
		super(message,th);
	}

	public CheckedCustomException(String message,Throwable th,boolean enableSuppression,boolean writeableStackTrace){
		super(message, th, enableSuppression, writeableStackTrace);
	}

	
	public static void main(String[] args) throws CheckedCustomException { 
          throw new CheckedCustomException("Checked exception Demo");
	}

	
}

Output of the above program is as below:

Exception in thread "main" com.masterjavatutorial.CheckedCustomException: Checked exception Demo
	at com.masterjavatutorial.CheckedCustomException.main(CheckedCustomException.java:29)

How to Create Custom Unchecked Exception Class:

Custom Checked Exception can be created in the following steps:

I.) Create a class and extend an unchecked exception class as super class
II.) Create different contructors of custom unchecked exception class and pass arguments in the super class constructor.
III.) throw custom unchecked exception in the class as and when required.

Unchecked exception class does not force either to throws at method level or catch that exception. Code compiles even without throws at the method level or catch that exception. It gets thrown at Runtime by JVM if exception occurs at Runtime.

All unchecked exception classes are subclass of RuntimeException.

package com.masterjavatutorial;

public class UnCheckedCustomException extends RuntimeException{

	private static final long serialVersionUID = 1L; 
	
	public UnCheckedCustomException(){
		super();
	}
	
	public UnCheckedCustomException(String message){
		super(message);
	}

	public UnCheckedCustomException(Throwable th){
		super(th);
	}
	
	public UnCheckedCustomException(String message,Throwable th){
		super(message,th);
	}

	public UnCheckedCustomException(String message,Throwable th,boolean enableSuppression,boolean writeableStackTrace){
		super(message, th, enableSuppression, writeableStackTrace);
	}

	
	public static void main(String[] args) { 
          throw new UnCheckedCustomException("UnChecked exception Demo");
	}

	
}

Output of the above program is as below:

Exception in thread "main" com.masterjavatutorial.UnCheckedCustomException: UnChecked exception Demo
	at com.masterjavatutorial.UnCheckedCustomException.main(UnCheckedCustomException.java:29)