html - JavaScript try-catch not working - Stack Overflow

I am new to Java Script. In the below code I am trying to create an error intentionally to learn how tr

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
Add a ment  | 

2 Answers 2

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744717279a4589694.html

相关推荐

  • html - JavaScript try-catch not working - Stack Overflow

    I am new to Java Script. In the below code I am trying to create an error intentionally to learn how tr

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信