Whether the Customized Exception is Checked or Unchecked Exception? How?
Asked
Active
Viewed 175 times
1
-
2If it inherits from `RuntimeException` it is unchecked. Otherwise it is checked. – khelwood Jul 07 '15 at 09:29
-
Under Exception class, comes both RunTimeException (Unchecked) and other Checked Exceptions. So how could we be so sure that our customized exception is checked if it inherits Exception class? – dgl viru Jul 07 '15 at 09:45
-
**Check whether it inherits from RuntimeException** – khelwood Jul 07 '15 at 09:49
4 Answers
2
If you do like this:
public class CustomException extends Exception
then your CustomException is checked exception
If you do like this:
public class CustomException extends RuntimeException
then your CustomException is unchecked exception

Garry
- 4,493
- 3
- 28
- 48
-
Under Exception class, comes both RunTimeException (Unchecked) and other Checked Exceptions. So how could we be so sure that our customized exception is checked if it inherits Exception class? – dgl viru Jul 07 '15 at 09:40
-
It is handled by the compiler. It check for hierarchy, basically the checked exception are created because they can occur at many points in the program and recovery from them is difficult or impossible and developer can handle them in code. – Garry Jul 07 '15 at 09:57
0
If an exception inherits from RuntimeException
then it is unchecked. Otherwise it is checked.

khelwood
- 55,782
- 14
- 81
- 108
0
It depends on what it inherits. If your custom exception is a subclass of RuntimeException
then it is unchecked exception.
And if your custom exception extends Exception
class then it is checked exception.
See the Differences between Runtime/Checked/Unchecked/Error/Exception for more details
0
depends on inheritance. if it inherits from RuntimeException it is unchecked. Otherwise it is checked

Manish Prajapati
- 392
- 2
- 11