There are two types of Exceptions in Java:
• Checked Exceptions
• Unchecked Exceptions
Checked Exceptions: These are the exceptions which occur during the compile-time of the program. The compiler checks at the compile time that whether the program contains handlers for checked exceptions or not. These exceptions must be handled to avoid a compile-time error by the programmer. These exceptions extend the Exception class . Checked exceptions are required to be caught. For example if we call the readLine() method with a BufferedReader object then the IOException may occur. For this, our method should have code to handle the IOException. Here is the list of checked exceptions.
• NoSuchFieldException
• InstantiationException
• IllegalAccessException
• ClassNotFoundException
• NoSuchMethodException
• CloneNotSupportedException
• InterruptedException
Unchecked Exceptions: Unchecked exceptions are the exceptions which occur during the runtime of the program. Unchecked exceptions extend the RuntimeException that is inherited from java.lang.Exception class. This type of exceptions are also called Runtime exceptions that are usually caused by data errors, like arithmetic overflow, divide by zero etc. Here is the list of unchecked exceptions.
• IndexOutOfBoundsException
• ArrayIndexOutOfBoundsException
• ClassCastException
• ArithmeticException
• NullPointerException
• IllegalStateException
• SecurityException
0 comments:
Post a Comment