package
org.training.exceptions;
public class
NegativeArraySize {
public static void main(String[]
args) {
int array[] =
{1,2,3,4,5};
try {
array
= new int[-8];
}catch(NegativeArraySizeException
nase) {
System.err.println("Negative
Array Size Exception has occured, check array initialization again. ");
}
for (int i: array) {
System.out.println(i);
}
}
}
Output:
Negative Array Size Exception has occurred, check array initialization again.
1
2
3
4
5
No comments:
Post a Comment