I am going to throw an exception with RangeError and want to check if I use it correctly and how to catch it better.
I have a function that can throw a RangeError OR TypeError like this
function saveNumber(val) { // Only accept numbers. if (typeof val !== 'number') { throw new TypeError(); } // Error if the number is outside of the range. if (val > max || val < min) { throw new RangeError(); } db.save(val); }
I would like to call it and only deal with RangeError. What is the best way to do this?
javascript try-catch
eddiec
source share