Thursday, 5 May 2016

*Checked vs Unchecked Exceptions in Java*

Checked vs Unchecked Exceptions:-

In Java, there two types of exceptions:
1) Checked: are the exceptions that are checked at compile time.
*If some code within a method throws a checked exception,

*the method must either handle the exception or it must specify the exception using throws keyword.
2) Unchecked are the exceptions that are not checked at compiled time.
*In C++, all exceptions are unchecked, so it is not forced by the compiler to either handle or specify the exception.
*It is up to the programmers to be civilized, and specify or catch the exception
*In Java exceptions under Error and RuntimeException classes are unchecked exceptions,
everything else under throwable is checked

No comments:

Post a Comment