Okay i hope i can clear this up.
First of all you are using throw wrong...
as you know a try catch (finally) looks like this:
Code:
]
try {
Block of code to try
}
catch(err) {
Block of code to handle errors
}
finally {
Block of code to be executed regardless of the try / catch result
}
and here is an example of using throw inside a try/catch
Code:
function myFunction()
var message, x;
message = document.getElementById("message");
message.innerHTML = "";
x = document.getElementById("demo").value;
try {
if(x == "") throw "Empty";
if(isNaN(x)) throw "Not a number";
if(x > 10) throw "Too high";
if(x < 5) throw "Too low";
}
catch(err) {
message.innerHTML = "Error: " + err + ".";
}
finally {
document.getElementById("demo").value = "";
}
}
As you can see it throws the message to the catch block. Then you have when you want your error to say. So what goes wrong in the try block gets thrown into the catch block.
Think of your catch block as its own function and the throw is how you call the function.
Bookmarks