JavaScript Try...Catch...Finally Statement Example

In JavaScript try catch finally statement are handle exceptions gracefully.

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>JavaScript try...catch...finally statement</title>
</head>
<body>
<pre>  <!-- Use pre element for work document.writeln() method -->
<script>
    function welcome(){
        document.writeln("welcome() : Hello world!");
    }
    function bye(){
        document.writeln("bye() : Good bye!");
    }
    
    try{
        welcome()
        asking()
    } catch(e){
        document.writeln("asking() : " + e);
    } finally{
        bye()
    }
</script>
</pre>
</body>
</html>

Run it...   »

Example Result