catch block catches the error, and executes a code to handle it: - Javascript Statement

Javascript examples for Statement:try catch finally

Description

catch block catches the error, and executes a code to handle it:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
try {/*from ww  w.j  a  v  a2  s. c o m*/
    methodDoesNotExist("Welcome guest!");
}
catch(err) {
    document.getElementById("demo").innerHTML = err.message;
}
</script>

</body>
</html>

Related Tutorials