A try without a catch clause sends its error to the next higher catch, or the window, if there is no catch defined within that try.

If you do not have a catch, a try expression requires a finally clause.

try {
    // whatever;
} finally {
    // always runs
}
Answer from kennebec on Stack Overflow
Discussions

language agnostic - Why use try … finally without a catch clause? - Software Engineering Stack Exchange
The classical way to program is with try ... catch. When is it appropriate to use try without catch? In Python the following appears legal and can make sense: try: #do work finally: #do some... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
January 23, 2012
[AskJS] I just found out that "finally" block runs even when "try" / "catch" block returns
This has been the case for every programming language which supports finally. More on reddit.com
🌐 r/javascript
9
29
December 20, 2021
javascript - What is the point of finally in a try..catch? - Stack Overflow
Is there any reason to put code in a finally block as opposed to just having code after the try...catch statement. More on stackoverflow.com
🌐 stackoverflow.com
Using `try`/`finally` without `catch` - Question - Scala Users
If I need to compute something but do some side effect before returning that value, is the correct idiom try/finally without catch ? e.g., def calculateSemesterAverage() = { import scala.io.Source def csv = Source.fromFile("some-file-to-parse.csv") try { for {line More on users.scala-lang.org
🌐 users.scala-lang.org
0
June 22, 2020
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Statements › try...catch
try...catch - JavaScript - MDN Web Docs - Mozilla
March 9, 2026 - For example, if an exception is thrown from the try block, even when there's no catch block to handle the exception, the finally block still executes, and the exception is thrown immediately after the finally block finishes executing.
Top answer
1 of 9
182

It depends on whether you can deal with the exceptions that can be raised at this point or not.

If you can handle the exceptions locally you should, and it is better to handle the error as close to where it is raised as possible.

If you can't handle them locally then just having a try / finally block is perfectly reasonable - assuming there's some code you need to execute regardless of whether the method succeeded or not. For example (from Neil's comment), opening a stream and then passing that stream to an inner method to be loaded is an excellent example of when you'd need try { } finally { }, using the finally clause to ensure that the stream is closed regardless of the success or failure of the read.

However, you will still need an exception handler somewhere in your code - unless you want your application to crash completely of course. It depends on the architecture of your application exactly where that handler is.

2 of 9
40

The finally block is used for code that must always run, whether an error condition (exception) occurred or not.

The code in the finally block is run after the try block completes and, if a caught exception occurred, after the corresponding catch block completes. It is always run, even if an uncaught exception occurred in the try or catch block.

The finally block is typically used for closing files, network connections, etc. that were opened in the try block. The reason is that the file or network connection must be closed, whether the operation using that file or network connection succeeded or whether it failed.

Care should be taken in the finally block to ensure that it does not itself throw an exception. For example, be doubly sure to check all variables for null, etc.

🌐
Esdiscuss
esdiscuss.org › topic › try-without-catch-or-finally
try without catch or finally
The lack of parentheses make it clear that the word following 'except' is not the error parameter, and the lack of braces clearly means the catch-phrase ends at the semicolon. It could even be immediately followed by a finally, which I think yields some terse, but useful syntax that's intuitive and consistent. ... Why is the argument and curly brace syntax required for except? Why not simply allow: try { throw ExceptionalException; } catch dosubroutine(); which for the convenience of Jussi's original ask: try { //fail } catch null; (or if you prefer, a noop call).
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript try without catch
How to Try Without Catch in JavaScript | Delft Stack
February 2, 2024 - We throw the error by dividing 0 with 0. It will throw a NaN error which the finally block will not catch because of the missing catch block, and print the "Final Call" statement inside the finally block.
Find elsewhere
🌐
Reddit
reddit.com › r/javascript › [askjs] i just found out that "finally" block runs even when "try" / "catch" block returns
r/javascript on Reddit: [AskJS] I just found out that "finally" block runs even when "try" / "catch" block returns
December 20, 2021 -

Even though I've been writing JS for years, I never realized that "finally" block always runs within the function, even when "try" / "catch" block returns a value

function testFinally() {
  try {
    console.log("try block");
    return "return value";
  } finally {
    console.log("finally called");
  }
}

console.log(testFinally());

Running this will log:

try block
finally called
return value

Very useful in case you have to run a callback that may fail, but you have to do some required setup / teardown around the callback. Suppose you wanna do something like this:

let isCallbackRunning = false;

function runCallback(callback) {
  if (!isCallbackRunning) {
    isCallbackRunning = true;
    const result = callback();
    isCallbackRunning = false;
    return result;
  }
}

Well, the problem is, if callback() throws, isCallbackRunning = false will not run, which means when you call runCallback next time, it will permanently get stuck and not actually run the callback.

So we really need to maintain isCallbackRunning correct at all times, regardless of whether callback function throws or not. So the way to do this is this:

function runCallback(callback) {
  if (!isCallbackRunning) {
    isCallbackRunning = true;
    try {
      return callback();
    } finally {
      isCallbackRunning = false;
    }
  }
}

What's curious is that, imagine callback() doesn't throw. Even though the result is immediately returned in the try block, finally block will actually run right before that, ensuring our teardown still gets called and making code simpler.

🌐
Bennadel
bennadel.com › blog › 2154-i-finally-understand-the-finally-part-of-a-try-catch-control-statement.htm
I Finally Understand The Finally Part Of A Try/Catch Control Statement
April 21, 2020 - In Javascript, I don't do a whole lot of Try/Catch; I mostly used it in this example because the Eloquent Javascript book is in, well, Javascript :) I wonder if you can use a Try without a Catch in ColdFusion; I guess you can. I think the CFFinally tag may have only been introduced in ColdFusion 9 (the latest release). ... Yeah, good thought. But, also, this only makes sense if the CFCatch's are going to halt the processing of the given call stack (otherwise, you could really just factor the Finally out of the try/catch).
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Promise › finally
Promise.prototype.finally() - JavaScript - MDN Web Docs
January 8, 2026 - For example, both Promise.reject(3).finally(() => { throw 99; }) and Promise.reject(3).finally(() => Promise.reject(99)) reject the returned promise with the reason 99. Like catch(), finally() internally calls the then method on the object upon which it was called.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › error handling
Error handling, "try...catch"
In other words, the function may finish with return or throw, that doesn’t matter. The finally clause executes in both cases. ... Please note that result and diff variables in the code above are declared before try...catch.
🌐
JavaScripting
javacripting.com › home › javascript syntax › javascript try without catch: when to use finally
JavaScript Try Without Catch: When to Use Finally
February 27, 2026 - In a pure try without catch, there is no error handler inside the construct; instead, JavaScript guarantees that the finally block runs after the try completes, whether the code threw an error, returned early, or finished normally.
🌐
DocStore
docstore.mik.ua › orelly › webprog › jscript › ch06_17.htm
try/catch/finally (JavaScript: The Definitive Guide, 4th Edition)
The try/catch/finally statement is JavaScript's exception-handling mechanism. The try clause of this statement simply defines the block of code whose exceptions are to be handled. The try block is followed by a catch clause, which is a block of statements that are invoked when an exception ...
🌐
Quora
quora.com › Can-try-be-used-without-catch
Can try be used without catch? - Quora
Use try+finally when you need deterministic cleanup (closing files, releasing locks) but want exceptions to continue propagating. Avoid empty catch blocks that swallow exceptions; prefer letting exceptions propagate or handle them intentionally.
🌐
Scala Users
users.scala-lang.org › question
Using `try`/`finally` without `catch` - Question - Scala Users
June 22, 2020 - If I need to compute something but do some side effect before returning that value, is the correct idiom try/finally without catch ? e.g., def calculateSemesterAverage() = { import scala.io.Source def csv = Source.fromFile("some-file-to-parse.csv") try { for {line
🌐
Codeguage
codeguage.com › v1 › courses › js › exceptions-basics
JavaScript Exceptions - try...catch...finally
Save this precious resource of yours and instead learn from "mini" courses · Something you can consume while you're on commute, on work, or even a holiday. (Wow!)
🌐
W3Schools
w3schools.com › js › js_errors.asp
JavaScript Error Statements
In JavaScript, the try statement is used to handle errors (also called exceptions) that may occur during code execution - without stopping the entire program. The try statement works together with catch. Sometimes it works with finally.
🌐
DEV Community
dev.to › ycmjason › stop-hating-try-catch-in-javascript-just-use-this-pattern-5b92
TRY {} CATCH {} ‒ FIXED! (with a surprisingly old trick) - DEV Community
May 11, 2025 - It keeps things local and avoids the weird side effects of broad try-catch blocks. If it ever feels messy, you can always extract it into a function and give it a name. I usually only do that when I actually need to reuse the error handling. (Which is also a nice way to reuse logic without abstracting too early, you know, naming is hard.) Curious — have you used IIFE in your projects before, or is this your first time seeing it used like this? ... I cook delicious TypeScript / JavaScript nuggets.