I want to catch an error when access outside of array's bounds happens but it doesn't seem to throw an error.
let arr = [2,4,5];
let test = arr[3];
console.log(test);
I know that I can test for undefined and throw an error
if (arr[3] === undefined) throw new Error();
but how come I can't just do try and catch it like the following.
let arr = [2,4,5];
try {
let tmp = arr[3];
} catch(e) {
lastIndex = findLastIndex(arr, high / 2, high);
break;
}
if (i < arr.length) tmp = arr[i] else ….