7.4. What happens when an exception is thrown?

[8.2] Create a try-catch block and determine how exceptions alter normal program flow

[8.4] Create and invoke a method that throws an exception

In this section, we’ll uncover what happens when an exception is thrown in Java. We’ll work through several examples to understand how the normal flow of code is disrupted when an exception is thrown. We’ll also define an alternative program flow for code that may throw exceptions using try-catch-finally blocks.

As with all other Java objects, an exception is an object. All types of exceptions subclass java.lang.Throwable. When a piece of code hits an obstacle in the form of an exceptional condition, it creates an object ...

Get OCA Java SE 8 Programmer I Certification Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.