Unchecked Exception in Java is those Exceptions whose handling is not verified during Compile time.
Unchecked Exceptions mostly arise due to programming errors like accessing method of a null object, accessing element outside an array bonding or invoking method with illegal arguments.
Some important's points
- Runtime Exception are also known as unchecked exception.
- UnCheckedException are mostly programming mistakes.
- Unchecked Exception are of RuntimeException.
- Unchecked Exception is direct sub Class of RuntimeException.
Examples of UncheckedExceptions:-
- ArithmeticException
- NullPointerException
- ArrayIndexOutOfBoundException
- NegativeArraySizeException.....etc
Through Example:
class DemoUncheckedExceptions {
public static void main(String args[])
{
int num1=20;
int num2=0;
/*If I'm dividing with an integer with 0
* it should throw ArithmeticException*/
int result=num1/num2;
System.out.println(result);
}
}
No comments:
Post a Comment