JavaScript try-catch error

I am new to Java Script. In the code below, I am trying to create an error intentionally to find out how to try ... to catch the job. But nothing works.

<html>
<body>
<p id="demo"></p>
<script>
try {
    adddlert("Hi User!");
}
catch(Error e) {
    document.getElementById("demo").innerHTML = e.message;
}
</script>
</body>
</html>

What am I missing?

+4
source share
2 answers

Syntax error:

Change catch (Error e)how catch (e).

Additional information: http://www.w3schools.com/js/js_errors.asp

+5
source

try {
    adddlert("Hi User!");
}
catch(e) {
    document.getElementById("demo").innerHTML = e.message;
}
<html>
<body>
<p id="demo"></p>
</body>
</html>
Run codeHide result
+6
source

All Articles