Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript try-catch not working

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?

like image 244
Rajuu Avatar asked Dec 19 '22 11:12

Rajuu


1 Answers

try {
    adddlert("Hi User!");
}
catch(e) {
    document.getElementById("demo").innerHTML = e.message;
}
<html>
<body>
<p id="demo"></p>
</body>
</html>
like image 99
Agus Putra Dana Avatar answered Jan 13 '23 03:01

Agus Putra Dana