How do I use multi-catch statement?

The multi-catch is a language enhancement feature introduces in the Java 7. This allow us to use a single catch block to handle multiple exceptions. Each exception is separated by the pipe symbol (|).

Using the multi-catch simplify our exception handling and also reduce code duplicates in the catch block. Let’s see an example below:

package org.kodejava.example.lang;

import java.sql.SQLException;

public class MultiCatchDemo {
    public static void main(String[] args) {
        MultiCatchDemo demo = new MultiCatchDemo();
        try {
        } catch (IOException | SQLException | ClassNotFoundException e) {

    private void callA() throws IOException {
        throw new IOException("IOException");

    private void callB() throws SQLException {
        throw new SQLException("SQLException");

    private void callC() throws ClassNotFoundException {
        throw new ClassNotFoundException("ClassNotFoundException");

Wayan Saryada

Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. You can support my works by donating here. Thank you 🥳

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.