How would you handle multiple exceptions in a single catch block?

Java allows multiple exceptions to be handled within a single catch block using the multi-catch feature introduced in Java 7. This is useful when different exception types require the same handling logic, reducing code duplication and improving readability.

Key Points

Example

If both file operations and database operations require the same logging and cleanup process, they can be handled using a single catch block.

import java.io.IOException;
import java.sql.SQLException;

public class Demo {

    static void loadReport(boolean fromDatabase) throws IOException, SQLException {
        if (fromDatabase) {
            throw new SQLException("Database is not reachable");
        }
        throw new IOException("Report file not found");
    }

    public static void main(String[] args) {

        try {
            loadReport(true);
        } catch (IOException | SQLException e) {
            System.out.println("Exception handled: " + e.getMessage());
        }
    }
}

Output

Exception handled: Database is not reachable

Benefits of Multi-Catch

Interview Tip

A concise interview answer is

Multiple exceptions can be handled in a single catch block using the pipe (|) operator. This feature, known as multi-catch, is useful when different exceptions require the same handling logic, helping reduce duplicate code and improve maintainability.

Last updated: 11 November 2026

Previous question: What is an exception, and what is the difference between checked and unchecked exceptions?

Next question: What is the difference between a Throwable and an Exception in Java?

More Core Java - Level II interview questions

All Core Java - Level II questions