3

In my web application created a User defined exception extends with Exception.Is it Checked or unchecked exception

public class InvalidDataException extends Exception{


        public InvalidDataException() {
        super();
        // TODO Auto-generated constructor stub
    }
    /**
     * @param arg0
     */
    public InvalidDataException(String message) {
        super(message);
        // TODO Auto-generated constructor stub
    }
}
user1357722
  • 7,088
  • 13
  • 34
  • 43

5 Answers5

9

Only those exceptions that are subclasses of RuntimeException are considered unchecked.

Yours isn't, and therefore is a checked exception.

NPE
  • 486,780
  • 108
  • 951
  • 1,012
  • 1
    But defualtly runtime exception extends with Exception.Can i say Unchecked Exception – user1357722 May 02 '12 at 14:42
  • @user1357722: If you want an unchecked exception, extend RuntimeException. If you don't, don't. Simple as that. – NPE May 02 '12 at 14:43
1

It's a checked exception class. Any class which extends Exception class will be a user defined Checked exception class. Where as any class which extends RuntimeException will be Unchecked exception class.

Srinivas
  • 1,780
  • 1
  • 14
  • 27
0

You could have used IllegalArgumentException.

This exception is unchecked whereas yours is checked as @duffymo & @aix commented.

Snicolas
  • 37,840
  • 15
  • 114
  • 173
0

User Defined exceptions are checked exceptions because they are extended with Exception class which is super class for all the exceptions occured,where as unchecked exceptions are extended with run time Exceptions.

0

THere are two classes call as partially checked exception.

1.) Exception class

2.) throwable class

It calls partially checked because some of their subclasses are Unchecked. So you have extended the Exception class then it's Checked exception

B_Ali_Code
  • 65
  • 10