Page 383 - CITS - Computer Software Application -TT
P. 383
COMPUTER SOFTWARE APPLICATION - CITS
Unchecked Exceptions
The unchecked exceptions are just opposite to the checked exceptions. The compiler will not check these
exceptions at compile time. In simple words, if a program throws an unchecked exception, and even if we didn’t
handle or declare it, the program would not give a compilation error. Usually, it occurs when the user provides bad
data during the interaction with the program.
Note: The RuntimeException class is able to resolve all the unchecked exceptions because of the
child-parent relationship.
UncheckedExceptionExample1.java
class UncheckedExceptionExample1 {
public static void main(String args[])
{
int postive = 35;
int zero = 0;
int result = positive/zero;
//Give Unchecked Exception here.
System.out.println(result);
}
}
In the above program, we have divided 35 by 0. The code would be compiled successfully, but it will throw an
ArithmeticException error at runtime. On dividing a number by 0 throws the divide by zero exception that is a
uncheck exception.
Output:
370
CITS : IT&ITES - Computer Software Application - Lesson 101 - 108