RuntimeExceptions Are Unchecked Exceptions

All exception types that are direct or indirect subclasses of RuntimeException (package java.lang) are unchecked exceptions. These are typically caused by defects in your program’s code. Examples of unchecked exceptions include:

ArrayIndexOutOfBoundsExceptions (discussed in Chapter 7)—You can avoid these by ensuring that your array indices are always greater than or equal to 0 and less than the array’s length.

ArithmeticExceptions (shown in Fig. 11.3)—You can avoid the ArithmeticException that occurs when you divide by zero by checking the denominator to determine whether it’s 0 before performing the calculation.

Classes that inherit directly or indirectly from class Error (Fig. 11.4) are unchecked ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.