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
Can I use a try/catch in JavaScript without specifying the catch argument/identifier? - Stack Overflow
I was wondering if there is a way to not specify the argument when doing a JS try/catch. Every time I try this though, the try/catch doesn't work. The working version: try{ //Breaking code } ca... More on stackoverflow.com
🌐 stackoverflow.com
Can I break a try - catch in JS without throwing exception?
I'd like to silently break a try - catch in the try block if a condition applies. ( Without throwing an unneccessary exception ) More on stackoverflow.com
🌐 stackoverflow.com
try without catch/finally is not documented
effectively hiding any exceptions in try block. Either fix implementaion (require either finally or catch block), or documentation (say that catch/finally is optional and mean empty body in that case). More on github.com
🌐 github.com
16
April 28, 2015
🌐
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 - In today's post, we'll learn about try statements without implementing catch in JavaScript.
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.

🌐
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.)
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-re-write-the-code-sample-without-try-catch-block
How to re-write the code sample without try/catch block ? - GeeksforGeeks
July 23, 2025 - In the above example, the method throws an exception during execution and because there is a try-catch block for exception handling, the program executes successfully without terminating abnormally!
Find elsewhere
🌐
DEV Community
dev.to › jimjja › error-handling-without-try-catch-blocks-4kok
Error handling without try/catch blocks - DEV Community
January 20, 2021 - The TypeScript type predicate result is CustomError will automatically cast the result to CustomError if the returned condition is true. One way to see this in action is to build an abstraction for an HTTP client. The HTTP client can extend the ErrorValidator class so the validation functions can be easily accessible by the client instance. ... class HttpClient extends ErrorValidator { public async request<T>( url: string, options?: RequestInit ): Promise<IResponse<T>> { return fetch(url, options) .then((response) => response.json()) .then((result: T) => result) .catch((error) => new CustomError(error)); } }
🌐
DEV Community
dev.to › richardshaju › stop-using-try-catch-a-better-way-to-handle-errors-in-javascript-14cm
Stop Using Try-Catch: A Better Way to Handle Errors in JavaScript - DEV Community
November 3, 2024 - There’s no need for nested try-catch blocks, making the code cleaner and more direct. Cleaner Code: With ?=, you can handle multiple potential errors in a single line, without using extra try-catch blocks.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Statements › try...catch
try...catch - JavaScript - MDN Web Docs - Mozilla.org
March 9, 2026 - The try...catch statement is comprised of a try block and either a catch block, a finally block, or both. The code in the try block is executed first, and if it throws an exception, the code in the catch block will be executed. The code in the finally block will always be executed before control ...
🌐
GitHub
github.com › jashkenas › coffeescript › issues › 3958
try without catch/finally is not documented · Issue #3958 · jashkenas/coffeescript
April 28, 2015 - try 42 is NOT (!) syntax error, and converted to try { 42; } catch (_error) {} effectively hiding any exceptions in try block. Either fix implementaion (require either finally or catch block), or documentation (say that catch/finally is ...
Author   socketpair
🌐
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.
🌐
Quora
quora.com › Can-try-be-used-without-catch
Can try be used without catch? - Quora
Allowed: try can have finally without except. Syntax: try: ... finally: ... Purpose: ensure cleanup; exceptions propagate after finally runs. ... Equivalent construct: begin ... ensure ... end. begin can omit rescue (Ruby’s catch) and use ensure for cleanup.
Top answer
1 of 6
61

I don't need the catch block.

But you do need to catch. The behavior of your code with a catch block is to catch any exception, and then forget that it happened. So any exception that tries to pass through will stop, and your code will basically pretend that the try block executed successfully.

So you want a naked try block to act like it catches an exception and ignores it. Here's the thing: a default case is meant to be a common case, one that is useful by many users and not error prone. if doesn't typically require an else because there are many cases where you have nothing to do.

I know nothing about why you want to drop exceptions on the floor and pretend they didn't happen. I'm willing to accept that you have some good justification for doing so. But the fact is, in the general case, it's not a good idea. Most programmers don't want to do it, and there are good arguments to say that it is generally unwise to do this sort of thing.

A good language will let you do something unwise. But a good language will not let you do something unwise by accident. Since the behavior you want is generally unwise, languages tend to make you explicitly request it.

2 of 6
34

As others have pointed out, there are good reasons why a plain try is not allowed in JavaScript, or in most other languages that have the same syntax:

  • It's not even obvious what it should do: for consistency with try...finally, a try with no catch should arguably just let any exceptions through without, well, catching them. But without a catch or a finally block, such a plain try would be useless.

  • Most likely, a try without a catch (or a finally) is just an editing mistake, just like an else without an if. It's a good thing for the parser to notice and inform you of such mistakes.

  • Catching exceptions and ignoring them completely is an unusual and risky thing to do, since it's easy to catch more than you expected. If you really want to do it, it's a good thing that the language at least forces you to be explicit about it.

In particular, note that your example code is kind of fragile and makes it easy to introduce subtle bugs that can be hard to detect and debug, since everything will seem to behave normally. For instance, let's make the following seemingly harmless change to your example:

// setting defaults ahead of try - no need for a catch block?
var setting = 10;
var myRegEx = optimizeRegEx("/123/g");
var supportsRegEx2 = false;

try {
    const utils = require("applicationutils");
    setting = 20;
    myRegEx = optimizeRegEx("/123/gm");
    supportsRegEx2 = true;
}
catch (e) {} // why does JS force me to do this?

Can you see what might go wrong here? I'll give you a moment to think about it...

OK, so what happens if optimizeRegEx() has a bug and crashes when given the input "/123/gm"? That exception will also be caught and ignored, since it happens inside the try block, so you'll never see it! Worse, now your variables will end up in an inconsistent state: setting will be 20 and the applicationutils module will be loaded, but myRegEx will still have its original value and supportsRegEx2 will be false. Have fun debugging that!

So how would you do that safely? Well, the first thing would be to ensure that the variables always end up in a consistent state, at least. One way to do that would be to (re)set them to their defaults in the catch block:

// these will be set inside the try/catch block below
var setting, myRegEx, supportsRegEx2;

try {
    const utils = require("applicationutils");
    setting = 20;
    myRegEx = optimizeRegEx("/123/gm");
    supportsRegEx2 = true;
}
catch (e) {
    // something went wrong, probably require() failed: use fallback defaults instead
    setting = 10;
    myRegEx = optimizeRegEx("/123/g");
    supportsRegEx2 = false;
}

That's a bit better: any exceptions from optimizeRegEx("/123/gm") will still be silently thrown away, but at least all the variables will end up with their default values if that happens.

Even better would be to fix the code to only catch the specific exception thrown when the require() fails. Unfortunately JavaScript makes this harder than it should be, since it doesn't support conditional catch clauses. But we can at least follow the general principle of having as little code as possible inside each try to avoid catching unexpected exceptions, and we can also inspect the caught exception inside the catch block and rethrow it if it's not what we expected to see:

// setting defaults ahead of try
var setting = 10;
var myRegEx = optimizeRegEx("/123/g");
var supportsRegEx2 = false;

// try loading utils, catch and ignore module loading error
var utils = null;
try {
    utils = require("applicationutils");
}
catch (e) {
    if (e.code !== 'MODULE_NOT_FOUND') throw e;  // rethrow any unexpected errors
}

// adjust variables if the module loaded without errors
if (utils !== null) {
    setting = 20;
    myRegEx = optimizeRegEx("/123/gm");
    supportsRegEx2 = true;
}

(Error code test based on this answer on SO.)

Now we're only ignoring those errors that come from the statement that we expect to throw them and which also look like the error we expect. This minimizes the risk of us accidentally ignoring an error that wasn't the harmless one we were expecting, and thus makes the code more robust and easier to debug.


Regarding your actual use case (now that you've described it), it seems to me that what you really want is a wrapper function like this:

function tryRequire(moduleName) {
    try {
        return require(moduleName);
    }
    catch (e) {
        if (e.code === 'MODULE_NOT_FOUND') return null;  // adjust this as needed to detect module loading errors in your environment
        throw e;  // rethrow any unexpected errors
    }
}

This way, you can just do const foo = tryRequire('foo'), and then check whether the module was successfully loaded based on whether foo is null.

🌐
Medium
medium.com › tech-buddy › async-await-without-try-catch-in-javascript-fdd38abf7e90
Async await without try catch in JavaScript | by Sai Umesh Dhanewar | Tech Buddy | Medium
June 14, 2021 - Async await without try catch in JavaScript Before introduction to async await my typical code used to look like below. If your using Express framework you would be interested in this …
🌐
Medium
medium.com › @asiripiyajanaka › no-more-try-catch-better-ways-to-handle-errors-in-javascript-7ca9af60be22
No more try-catch, Better Ways to Handle Errors in JavaScript | by Asiri Piyajanaka | Medium
October 27, 2024 - Calling handleError: Instead of wrapping each data fetch in try-catch, we wrap each call in handleError. This makes it clear that any errors will be logged automatically without cluttering the main function with error handling code.