try Block

A block containing code that may throw an exception.

What is try Block in Java?

try Block — A block containing code that may throw an exception.

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