25.9 Exceptions

[Note: This section may be read after studying Chapter 6 and the preceding sections of Chapter 25.]

In Section 6.6, we introduced Java’s exception-handling mechanism, showing how to catch an exception that occurred when we attempted to use an out-of-bounds array index. In JShell, catching exceptions is not required—it automatically catches each exception and displays information about it, then displays the next JShell prompt, so you can continue your session. This is particularly important for checked exceptions (Section 11.5) that are required to be caught in regular Java programs—as you know, catching an exception requires wrapping the code in a try...catch statement. By automatically, catching all exceptions, JShell makes ...

Get Java How To Program, Late Objects, 11th 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.