Write A Java Program To Implement The Exception Handling
Ex: No: 13 EXCEPTIONS HANDLING IN JAVA
Aim:To write a java program to implement the exception handling.
Algorithm:
Step 1: Start the programs.
Step 2: Include the import statement.
Step 3: Declare the main class method.
Step 4: Declare the class and definite them.
Step 5: In that through a exception in the try.
Step 6: The exception will be caught by the catch block.
Step 7: Stop the program.
Program:
import java.io.*;
public class ExceptionTest
{
public static void main(String args[])
{
try
{
int a[]=new int[2];
System.out.println("access element three:"+a[3]);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Exception thrown:"+e);
}
System.out.println("out of the block");
}
}
Output:
Exception thrown: java.lang.ArrayIndexOutOfBoundsException:3
Out of the block
Result:
Thus the implementation of JAVA program for exception handling is executed and the output has been verified.
0 comments:
Post a Comment