ArrayStoreException In Java Example
Chapter:
Exception Handling
Last Updated:
09-09-2017 15:31:31 UTC
Program:
/* ............... START ............... */
public class JavaArrayStoreException {
public static void main(String... args) {
Object[] val = new Integer[4];
val[0] = 5.8;
}
}
/* ............... END ............... */
Output
Exception in thread "main" java.lang.ArrayStoreException: java.lang.Double
at ExceptionHandling.JavaArrayStoreException.main(JavaArrayStoreException.java:7)
Notes:
-
ArrayStoreExceptionon is thrown when there has been made an attempt to store the wrong type of object into an array of objects.
- In the above you can see that an integer array is declared with size four, and in the next step it is trying to assign double value and throwing java runtime exception : java.lang.ArrayStoreException.
- ArrayStoreException()- Constructs an ArrayStoreException instance with no detail message.
- ArrayStoreException(String s) - Constructs an ArrayStoreException instance with the specified detail message.
Tags
java.lang.ArrayStoreException, ArrayStoreException, Java Exception