I am confused about the Javascript exception handling I wanted to clear which error can Javascript catch or which can only be handling with if elses like in case below in first case I end up into catch block because of undefined variable but in other case I stayed in the try block(and would have to use if else for catching that) inspiteof both are "not defined"
first:
try {
var x = 90;
var value = x / y;
}
catch (err) {
document.write(err.name + ": " + err.message + "<br/>");
}
second :
function add(x, y) {
var resultString = "Hello! The result of your math is: ";
var result = x + y;
// return resultString + result; not returning anything; hence, "undefined" also
}
try {
var addResult = add(2, 3);
document.write(" the result is : " + addResult + "<br/>");
} catch (err) {
document.write(err.name + ": " + err.message + "<br/>");
}
Why I am not ending up in to catch block in second case also?
Please clear my understanding.