I am new to Java Script. In the below code I am trying to create an error intentionally to learn how try...catch works. But nothing is running.
<html>
<body>
<p id="demo"></p>
<script>
try {
adddlert("Hi User!");
}
catch(Error e) {
document.getElementById("demo").innerHTML = e.message;
}
</script>
</body>
</html>
What I am missing?
I am new to Java Script. In the below code I am trying to create an error intentionally to learn how try...catch works. But nothing is running.
<html>
<body>
<p id="demo"></p>
<script>
try {
adddlert("Hi User!");
}
catch(Error e) {
document.getElementById("demo").innerHTML = e.message;
}
</script>
</body>
</html>
What I am missing?
Share Improve this question edited Sep 24, 2014 at 12:53 Mithun Satheesh 27.9k14 gold badges79 silver badges102 bronze badges asked Sep 22, 2014 at 13:55 RajuuRajuu 434 bronze badges 1- 3 Always have the browser developer console open. – Pointy Commented Sep 22, 2014 at 13:56
2 Answers
Reset to default 6
try {
adddlert("Hi User!");
}
catch(e) {
document.getElementById("demo").innerHTML = e.message;
}
<html>
<body>
<p id="demo"></p>
</body>
</html>
Syntax Error:
Change your catch (Error e)
as catch (e)
.
More Info: http://www.w3schools./js/js_errors.asp