Program :To demonstrate exception handling.
Program
package exam;
import java.io.*;
public class MyArrExce
{
public static void main(String args[])
{
int n=0,i,j,t;
int a[]=new int[5];
DataInputStream in= new DataInputStream(System.in);
try
{
System.out.println("Enter the no: of elements : ");
n=Integer.parseInt(in.readLine());
System.out.println("Enter the elements of array : ");
for(i=0;iOutput
Enter the no: of Elements :
5
Enter the elements of array :
23
6
36
99
10
The sorted array is :
99
36
23
10
6
Enter the no: of elements :
6
Enter the elements of array :
23
6
36
99
10
29
Error : Array index out of bounds.
Java Exception Handling is a post from ShoutToWorld - Let's Learn Let's Shout - Helping bloggers and developers.