Exception Handling

Using try, catch, and related statements to respond to failures.

What is Exception Handling in Java?

Exception Handling — Using try, catch, and related statements to respond to failures.

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