Checked and Unchecked Exception in Java
Checked and Unchecked Exceptions are the two types of Exceptions in java. Both will cause issues in our programming piece of code.
Like other Checked Exceptions handled via try catch block and are normally occur while compile time and its inherit the Exception class. The other one is UnChecked is Runtime and inherit the RunTime.
Examples of Checked Exceptions are IOException
DataAccessException
ClassNotFoundException
InvocationTargetException
Normally we can use Checked exceptions when connection to a database or any other IO Operations, because the chance of Exception is high.
Examples of UnChecked Exceptions are NullPointerException
ArrayIndexOutOfBound
IllegalArgumentException
IllegalStateException
Normally the Unchecked Exceptions occur due to bad programming code.
In Java 7 checked exceptions can be avoided by multi catch operations.
Conclusion:
Both Checked and Unchecked Exceptions are handled by using try and catch blocks.
Checked Exceptions are occurred during Compile Time.
Use multi catch blocks to avoid this from java 7.
No comments:
Post a Comment