+ 7
Why doesn't the code generate ArrayIndexOutOfBoundsException?
The code should produce two errors: 1.ArrayIndexOutOfBoundsException when I tried to access the 8th index of an array of size 4. 2. ArithmeticException when I divided by 0. It only throws the Arithmetic one. https://code.sololearn.com/c4RGf6V66C9H/?ref=app
5 Réponses
+ 7
array[8] = 40/0;
In programming, the values to the right of the equals sign is evaluated first before it is assigned to a variable. Therefore, the Arithmetic exception and finally blocks are executed instead of the ArrayIndexOutOfBoundsException.
To prove my point check the following:
https://code.sololearn.com/cl8RDsrSB3MW/?ref=app
+ 5
No problem. We are all here to learn. I'm just a noob compared to the others here but I love learning from my own mistakes. 😆
+ 1
In java if you declare int arr[10] and trying to point on arr[10]=50 or anything else this exception is generated...
Because it is invalid location...
+ 1
Whenever We try to assign Variable a value the Variable which we are trying to be assigned a value is placed on the left side of assignment operator....and the value is placed on the right........if it is an expression it would be evaluated first and then the resulting value would be assigned to the variable.....That’s why it is throwing an ArithmaticException
0
Thanks Lambda_Driver for taking the time to explain it to me. 😄