I have been reading through the W3Schools tutorials on JavaScript, and am having a hard time understanding why my script is not throwing an exception. I expect it to throw an exception on the call document.getElementById("paragraphs"), because there is no id that equals paraghraphs. Please let me know why it's not throwing an Exception?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Design Patterns</title>
</head>
<body>
<button type="button" onclick="throwException()">Click Me!</button>
<p id="paragraph">I am a paragraph</p>
<script>
function throwException(){
try{
var errorContainer = document.getElementById("paragraphs").value;
}catch(err){
errorContainer.innerHTML="An error occured...";
}
}
</script>
</body>
</html>
throw "Hey I'm an exception!";withthrow new Error("Hey I'm an exception!");let me know if this helps... :)errorin thecatchblock. Did you meanerr?getElementById()doesn't throw an exception when it can't find the ID, it just returnsnull.