Wide view image of an Oops sign on Wooden block place over yellow background. With plenty of copy space.

Finally

We can add another block to try/catch. This is done with the “finally” keyword. What the finally code block does is run always. So even if there is an error, the finally block still runs. It runs regardless if there is an error or not. Here is the syntax…

try {
    let animal = newAnimal;
} catch(error){
    console.log(‘error: ‘, error);
} finally{
    console.log(‘this will always run’);
} 

Happy Coding!

Clay Hess

Share this post

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email
Skip to content