NegativeArraySizeException
KW.java
class KW { public static void main(String args[]) { int size=Integer.MIN_VALUE; System.out.println(size); String[] s=new String[size]; } }
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW -2147483648Exception in thread "main" java.lang.NegativeArraySizeException: -2147483648 at KW.main(KW.java:7) kodingwindow@kw:~$
Java program to handle the NegativeArraySizeException
KW.java
class KW { public static void main(String args[]) { int size=Integer.MIN_VALUE; try { String[] s=new String[size]; } catch(NegativeArraySizeException e) { System.out.println("Array underflow"); System.out.println(e.toString()); } } }
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW Array underflow java.lang.NegativeArraySizeException: -2147483648 kodingwindow@kw:~$
Comments and Reactions
What Next?
Java program to handle the OutOfMemoryError exception
Java program to handle divide by zero exceptionJava Regular ExpressionsAdvertisement