admin管理员组文章数量:1390472
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
本文标签: htmlJavaScript trycatch not workingStack Overflow
版权声明:本文标题:html - JavaScript try-catch not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744717279a2621479.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论