Custom Exception

An application-specific exception type created by extending an exception class.

What is Custom Exception in Java?

Custom Exception — An application-specific exception type created by extending an exception class.

class InvalidSeatCountException extends RuntimeException {
    InvalidSeatCountException(String message) {
        super(message);
    }
}

class Reservation {
    void reserve(int seats) {
        if (seats < 1) {
            throw new InvalidSeatCountException("Seat count must be positive");
        }
    }
}

Level: Journeyman · More Java terms at this level

Updated

In other subjects