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.

Answer from ChrisF on Stack Exchange
🌐
GitHub
github.com › topics › try-catch-finally
try-catch-finally · GitHub Topics · GitHub
A TypeScript library for handling `async` and `sync` errors without try-catch blocks. error-handling try-catch-finally might-fail error-as-values
🌐
GitHub
github.com › JuliaLang › julia › issues › 27554
try without catch should not catch · Issue #27554 · JuliaLang/julia
June 13, 2018 - This is a breaking change, but I feel like I should point it out now while 0.7 is still alpha, as there is a chance it can be fixed before 1.0 Right now: if you have a try block that has neither a catch nor a finally, it is the same as a...
Author   oxinabox
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
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
java - Does it make sense to do "try-finally" without "catch"? - Stack Overflow
@barth When there's no catch block the exception thrown in finally will be executed before any exception in the try block. So If there are two exceptions one in try and one in finally the only exception that will be thrown is the one in finally. This behavior is not the same in PHP and Python ... More on stackoverflow.com
🌐 stackoverflow.com
IL2CPP Windows - Try block ends without any catch, finally, nor fault handler - Unity 2019.4.35 - 2019.4.37
IL2CPP Windows - Try block ends without any catch, finally, nor fault handler - Unity 2019.4.35 - 2019.4.37 #550 ... Android builds fail on Windows with IL2CPP with: Try block ends without any catch, finally, nor fault handler. More on github.com
🌐 github.com
25
July 2, 2022
🌐
GitHub
github.com › JuliaLang › PkgDev.jl › issues › 149
Error in precompiling in Julia 1.0: "syntax: try without catch or finally" · Issue #149 · JuliaLang/PkgDev.jl
August 26, 2018 - [ Info: Precompiling PkgDev [149e707d-584d-56d3-88ec-740c18e106ff] ERROR: LoadError: LoadError: syntax: try without catch or finally Stacktrace: [1] include at ./boot.jl:317 [inlined] [2] include_relative(::Module, ::String) at ./loading.jl:1038 [3] include at ./sysimg.jl:29 [inlined] [4] include(::String) at /home/fabian/.julia/packages/PkgDev/DJ4wQ/src/PkgDev.jl:3 [5] top-level scope at none:0 [6] include at ./boot.jl:317 [inlined] [7] include_relative(::Module, ::String) at ./loading.jl:1038 [8] include(::Module, ::String) at ./sysimg.jl:29 [9] top-level scope at none:2 [10] eval at ./boot.
Author   fHachenberg
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.

🌐
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
🌐
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).
🌐
GitHub
github.com › getsentry › sentry-unity › issues › 550
IL2CPP Windows - Try block ends without any catch, finally, nor fault handler - Unity 2019.4.35 - 2019.4.37 · Issue #550 · getsentry/sentry-unity
July 2, 2022 - Android builds fail on Windows with IL2CPP with: Try block ends without any catch, finally, nor fault handler. Sample in CI: https://github.com/getsentry/sentry-unity/runs/5049914009?check_suite_focus=true Works on macOS with the same ve...
Author   bitsandfoxes
Find elsewhere
🌐
GitHub
github.com › eslint › eslint › issues › 7581
no-return-await must be aware of try/catch/finally · Issue #7581 · eslint/eslint
function asyncLog() { return new Promise((resolve) => { setTimeout(() => { console.log('first log'); resolve(true); }, 1000); }); } async function foo() { try { return await asyncLog(); // I really need this await, but no-return-await is complaining about it :( } finally { console.log('second log'); } } foo(); // first log // second log async function bar() { try { return asyncLog(); } finally { console.log('second log'); } } bar(); // second log // first log async function baz() { try { return asyncLog(); } catch (error) { // if asyncLog() rejects, error will be swallowed because I missed await :( } } not-an-aardvark ·
🌐
GitHub
github.com › tc39 › proposal-promise-finally › issues › 12
Would require finally in try catch too for async await · Issue #12 · tc39/proposal-promise-finally
November 19, 2016 - If finally promise callback is implemented for promises, then it would need a finally in case of try catch too atleast in case of async await. e.g.. function getBookList(url) { return getBooks(url) .then((books) => { console.log(books) }) .catch((error) => { console.log(error) }) .finally(() => { //do cleanup }) }); } and the async await version would need something like: async function getBookList(url) { try { let books = await getBooks(url); console.log(books); } catch (error) { console.log(error); } finally { // do cleanup } } No one assigned ·
Author   adnan-kamili
🌐
GitHub
github.com › laravel › framework › issues › 28087
Without catch, thrown exception result in error page · Issue #28087 · laravel/framework
April 2, 2019 - Laravel Version: 5.8 PHP Version: 7.3 Database Driver & Version: MySQL 5.7 Description: illuminate/mail#22 In theory, the try finally block can catch any exception without specific handling pro...
Author   lubobill1990
🌐
GitHub
github.com › fent › node-ytdl-core › issues › 1246
SyntaxError: Missing catch or finally after try · Issue #1246 · fent/node-ytdl-core
July 30, 2023 - SyntaxError: Missing catch or finally after try#1246 · Copy link · waltsh · opened · on Jul 30, 2023 · Issue body actions · Error caused when you search for a specific video (this rarely happens) but it also usually occurs when you request ...
Author   waltsh
🌐
DEV Community
dev.to › werliton › why-i-use-try-with-finally-without-catch-and-why-this-isnt-weird-code-2j92
Why I Use try with finally Without catch (and Why This Isn’t “Weird Code”) - DEV Community
2 weeks ago - This code is not trying to handle errors. ... “While this operation is running, a shared resource is locked. When it finishes — no matter how — that resource must be released.” · That’s the key idea. No — and this difference matters a lot. ... Without finally, cleanup is best-effort, not guaranteed.
🌐
GitHub
github.com › dotnet › csharplang › issues › 220
Discussion: `try` expression without `catch` for inline use · Issue #220 · dotnet/csharplang
March 3, 2017 - Proposal: try expression without catch for inline use Intent Sometimes it is not necessary to catch an exception, because you can either check side conditions or proceed though the expression is fa...
Author   lachbaer
🌐
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 · Yes. Actually both finally and catch blocks are optional and you can have a standalone try, but that wouldn’t ...
🌐
Reddit
reddit.com › r/javahelp › need help solving 'try' without 'catch', 'finally' or resource declarations error.
r/javahelp on Reddit: Need help solving 'try' without 'catch', 'finally' or resource declarations error.
May 5, 2022 -

I keep receiving this error: 'try' without 'catch', 'finally' or resource declarations. I’ve tried to add and remove curly brackets, add final blocks, and catch blocks and nothing is working.

https://codepen.io/angelineb/pen/KKQpbqV

Top answer
1 of 3
2
OK, it took me a bit to unravel your code because either you've done a great job of obfuscating your own indentation, or codepen absolutely demolished it. So the issue is where you've done try {/ serverSocket = new ServerSocket(1098,500); This try block exists, but it has no catch or finally. Try blocks always have to do one of three things, catch an exception, terminate with a finally (This is generally to close resources like database connections, or run some code that NEEDS to be executed regardless of if an error occurs), or be a try-with-resources block (This is the Java 7+ way of closing resources, like file readers). This block currently doesn't do any of those things. So I would question then is it actually a needed try block? If so, you need to complete it. If not, you need to remove it.
2 of 3
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
Medium
medium.com › @AlexanderObregon › how-javas-try-finally-blocks-work-without-catch-96e93be92ae5
How Java’s try-finally Blocks Work Without catch | Medium
March 4, 2025 - Java’s try-finally block is a reliable way to make sure important code runs before a method exits, no matter what happens. It runs even if an exception is thrown or a return statement is used, making it useful for tasks like closing files, releasing memory, or shutting down connections. The way Java compiles and executes finally guarantees that it always runs before control leaves the method, even when multiple finally blocks are involved. While catch is helpful for handling errors, it’s not always needed when the main goal is making sure resources are cleaned up properly.