@@ -423,6 +423,10 @@ public boolean hasValue(float value) {
423423 }
424424
425425
426+ private String exceptionText (int count , int index , String method ){
427+ return "The list size is " +count +". Trying to " +method +" the element at " +index +" which does not exist." ;
428+ }
429+
426430 /**
427431 * @webref floatlist:method
428432 * @brief Add to a value
@@ -431,7 +435,7 @@ public void add(int index, float amount) {
431435 if (index < count ) {
432436 data [index ] += amount ;
433437 } else {
434- throw new IndexOutOfBoundsException ( );
438+ throw new ArrayIndexOutOfBoundsException ( exceptionText ( count , index , "add" ) );
435439 }
436440 }
437441
@@ -444,7 +448,7 @@ public void sub(int index, float amount) {
444448 if (index < count ) {
445449 data [index ] -= amount ;
446450 } else {
447- throw new IndexOutOfBoundsException ( );
451+ throw new ArrayIndexOutOfBoundsException ( exceptionText ( count , index , "sub" ) );
448452 }
449453 }
450454
@@ -457,7 +461,7 @@ public void mult(int index, float amount) {
457461 if (index < count ) {
458462 data [index ] *= amount ;
459463 } else {
460- throw new IndexOutOfBoundsException ( );
464+ throw new ArrayIndexOutOfBoundsException ( exceptionText ( count , index , "mult" ) );
461465 }
462466 }
463467
@@ -470,7 +474,7 @@ public void div(int index, float amount) {
470474 if (index < count ) {
471475 data [index ] /= amount ;
472476 } else {
473- throw new IndexOutOfBoundsException ( );
477+ throw new ArrayIndexOutOfBoundsException ( exceptionText ( count , index , "div" ) );
474478 }
475479 }
476480
0 commit comments