What is an exception?
An exception is an event that occurs during the execution of a program that disrupts the normal flow of program execution.
Exception can occur at compile time also, which are known as compile time exceptions.
option 2 is correct. The exceptions that occur at run time belongs to RunTimeException class. Normal compile time exceptions belongs to Exception class.
all are true.
Exceptions are generally run time events, which disturbs the normal program execution flow.
If exceptions are not rectified or not handled properly then program will be terminated abruptly.
eg: Below program will throw ArrayIndexOutOfBoundsException, as the programmer is trying to access 10th index of the array. If array size is 10, then maximum index programmer can access is 10-1. This exception causes your program to terminate or end abruptly.
public class MainClass
{
public static void main(String args[])
{
int[] arr = new int[10];
for(int i=0; i<=10; i++){
arr[i] = i+1;
}
}
}
Back To Top