Using finally to ensure an operation is performed

Error handling can get fairly complicated. There may be cases where you want to allow an error to continue bubbling up the call stack to be handled at a higher level. In those cases, you may also need to perform some cleanup tasks. Often this can mean resetting some shared resource, but it could also simply be logging the current state of the application.

In this recipe, we'll see how to use finally to ensure that some code is executed, regardless of the error state.

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.