Home » Core Java » Custom Exception

Custom Exception

What is Custom Exception ?
1. User defined exception is called custom exception.

2. Using custom exception feature, user canĀ  define his/herĀ  own exception name

3. User can print custom message ,when the custom exception event occurs.

4. To define checked custom exception, custom exception class needs to extend java.lang.Exception class.

5. To define unchecked custom exception , custom exception class needs to extend java.lang.RuntimeException class.

Sample Program for Custom Exception ::
In the below program we have define custom Exception class “QualifyIITException” which is extending “java.lang.Exception” class.If a student gets a rank greater than 2500 ,then he/she is not eligible for IIT and getting the exception with some valid message.

Output ::


Leave a comment

Your email address will not be published. Required fields are marked *

eighteen − sixteen =