//B1. NEP Java Program to
catch Negative Array Size Exception.
//This exception is caused when the array is initialized to negative //values.
import java.io.*;
class Progb1
{
public static void main(String[] args)
{
try
{
int myArray[] = new int[-5];
for (int i = 0; i < myArray.length; i++)
{
System.out.println(myArray[i]);
}
}
catch (Exception e)
{
System.out.println("Negative Array size Exception!");
}
}
}
No comments :
Post a Comment