Compact Diagram

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Should ArithmeticException appear before RunTimeException in the list of catch blocks?

Answer:

Yes.

If RunTimeException appeared first, then its catch block would catch all RunTimeExceptions, including ArithmeticExceptions.

Compact Diagram

A more compact way of showing the hierarchy is:

Exception

    IOException

    AWTException

    RunTimeException
        ArithmeticException
        NoSuchElementException
            InputMismatchException
        IndexOutOfBoundsException
        Others

    Others

Don't memorize this diagram (for one thing, it is far from complete). But look at it to see what it says.

QUESTION 11:

Which should come first in the catch blocks:
ArithmeticException or IndexOutOfBoundsException?