Demonstrating the finally Block
Figure 11.5 demonstrates that the finally
block executes even if an exception is not thrown in the corresponding try
block. The program contains static
methods main
(lines 6–18), throwException
(lines 21–44) and doesNotThrowException
(lines 47–64). Methods throwException
and doesNotThrowException
are declared static
, so main
can call them directly without instantiating a UsingExceptions
object.
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.