Interview Q&A / Java

BeginnerQuick answer1 min readUpdated 3 Oct 2026

Can a try block exist without a catch block in Java?

SHORT ANSWER

Yes, as long as it has either a finally block or resources in try-with-resources. A bare try with neither is a compile error.

Explain it simply

Sometimes you do not know how to handle a problem, but you still must switch off the gas stove when leaving the kitchen. A try with only finally says "I will not deal with the exception here, but this cleanup must run anyway", and the exception continues on its way to the caller.

Example

java
static void run() {
    try {
        System.out.println("working");
        throw new RuntimeException("boom");
    } finally {
        System.out.println("cleanup");   // runs, then the exception moves up
    }
}

try {
    run();
} catch (RuntimeException e) {
    System.out.println("caught " + e.getMessage());
}
// prints:
// working
// cleanup
// caught boom

What to say in the interview

"Legal forms are try-catch, try-catch-finally, try-finally, and try-with-resources, which may have no catch or finally at all because the resources are closed automatically. Plain try alone does not compile. try-finally is useful when the current method cannot recover from the error but must still release something, such as unlocking a lock."

Common mistakes

  • Assuming finally catches the exception. It only runs code; the exception still propagates.

#java#exceptions#basics

Related questions

Practise more Java questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Java quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.