I was wondering if any of you tried to catch errors like RangeError, ReferenceError and TypeError using the JavaScript exception handling mechanism?
For example, for RangeError:
try {
var anArray = new Array(-1);
throw new RangeError("must be positive!")
}
catch (error) {
alert(error.message);
alert(error.name);
}
finally {
alert("ok, all is done!");
}
In the case above, am I throwing a new RangeError object?
In my code example, the alert (error.message) does not display the user message, which should be positive.
What can I do to throw my own RangeError object (and ReferenceError, TypeError)?
Best.
source
share