Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.Closeable;

public class Main {
    /**
     * Closes a specified Closeable, suppressing any checked exceptions. This has no effect if the closeable is null.
     *
     * @param closeable the object to close, may be null in which case this does nothing
     */
    public static void closeSilently(Closeable closeable) {
        if (closeable == null) {
            return; // silently ignore null
        }

        try {
            closeable.close();
        } catch (RuntimeException rethrown) {
            throw rethrown;
        } catch (Exception ignored) {
            // silently ignore checked exceptions
        }
    }
}