finally Block

A block that normally runs after try and catch whether an exception occurred or not.

What is finally Block in Java?

finally Block — A block that normally runs after try and catch whether an exception occurred or not.

class OrderReader {
    int readQuantity(String text) {
        try {
            return Integer.parseInt(text);
        } catch (NumberFormatException error) {
            return 0;
        } finally {
            closeReader();
        }
    }

    void closeReader() {
    }
}

Level: Journeyman · More Java terms at this level

Updated

In other subjects