11 Exception Handling: A Deeper Look

Objectives

In this chapter you’ll:

  • Learn why exception handling is an effective mechanism for responding to runtime problems.

  • Use try blocks to delimit code in which exceptions might occur.

  • Use throw to indicate a problem.

  • Use catch blocks to specify exception handlers.

  • Learn when to use exception handling.

  • Understand the exception class hierarchy.

  • Use the finally block to release resources.

  • Chain exceptions by catching one exception and throwing another.

  • Create user-defined exceptions.

  • Use the debugging feature assert to state conditions that should be true at a particular point in a method.

  • Learn how try-with-resources can automatically release a resource when the try block terminates.

Get Java How to Program, Early 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.