AI Workshop: learn to build apps with AI →
Errors and exceptions: Finally

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


To complete this statement, JavaScript has another clause called finally, which contains code that is executed regardless of the program flow—whether the exception was handled or not, and whether there was an exception or not:

try {
  //lines of code
} catch (e) {

} finally {

}

You can use finally without a catch block, to serve as a way to clean up any resources you might have opened in the try block, like files or network requests:

try {
  //lines of code
} finally {

}

Lessons in this unit:

0: Introduction
1: Types of errors
2: Creating exceptions
3: Handling exceptions
4: ▶︎ Finally
5: Nested try blocks