diff --git a/core/src/processing/data/FloatList.java b/core/src/processing/data/FloatList.java index 88c575a0a..1d06b772a 100644 --- a/core/src/processing/data/FloatList.java +++ b/core/src/processing/data/FloatList.java @@ -423,6 +423,10 @@ public class FloatList implements Iterable { } + private String exceptionText(int count, int index, String method){ + return "The list size is "+count+". Trying to "+method+" the element at "+index+" which does not exist."; + } + /** * @webref floatlist:method * @brief Add to a value @@ -431,7 +435,7 @@ public class FloatList implements Iterable { if (index < count) { data[index] += amount; } else { - throw new IndexOutOfBoundsException(); + throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "add")); } } @@ -444,7 +448,7 @@ public class FloatList implements Iterable { if (index < count) { data[index] -= amount; } else { - throw new IndexOutOfBoundsException(); + throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "sub")); } } @@ -457,7 +461,7 @@ public class FloatList implements Iterable { if (index < count) { data[index] *= amount; } else { - throw new IndexOutOfBoundsException(); + throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "mult")); } } @@ -470,7 +474,7 @@ public class FloatList implements Iterable { if (index < count) { data[index] /= amount; } else { - throw new IndexOutOfBoundsException(); + throw new ArrayIndexOutOfBoundsException(exceptionText(count, index, "div")); } } diff --git a/core/src/processing/data/IntList.java b/core/src/processing/data/IntList.java index 78b5d5c5a..0cf5f207b 100644 --- a/core/src/processing/data/IntList.java +++ b/core/src/processing/data/IntList.java @@ -407,16 +407,20 @@ public class IntList implements Iterable { data[index]++; } + private String exceptionText(int count, int index, String method){ + return "The list size is "+count+". Trying to "+method+" the element at "+index+" which does not exist."; + } + /** * @webref intlist:method * @brief Add to a value */ public void add(int index, int amount) { - if( index < count) { - data[index] += amount; + if (index < count) { + data[index] += amount; } else { - throw new IndexOutOfBoundsException(); - } + throw new IndexOutOfBoundsException(exceptionText(count, index, "add")); + } } /** @@ -424,11 +428,11 @@ public class IntList implements Iterable { * @brief Subtract from a value */ public void sub(int index, int amount) { - if( index < count) { - data[index] -= amount; + if (index < count) { + data[index] -= amount; } else { - throw new IndexOutOfBoundsException(); - } + throw new IndexOutOfBoundsException(exceptionText(count, index, "sub")); + } } /** @@ -436,11 +440,11 @@ public class IntList implements Iterable { * @brief Multiply a value */ public void mult(int index, int amount) { - if( index < count) { - data[index] *= amount; + if (index < count) { + data[index] *= amount; } else { - throw new IndexOutOfBoundsException(); - } + throw new IndexOutOfBoundsException(exceptionText(count, index, "mult")); + } } /** @@ -448,11 +452,11 @@ public class IntList implements Iterable { * @brief Divide a value */ public void div(int index, int amount) { - if( index < count) { - data[index] /= amount; + if (index < count) { + data[index] /= amount; } else { - throw new IndexOutOfBoundsException(); - } + throw new IndexOutOfBoundsException(exceptionText(count, index, "div")); + } }