Chapter 9

Exception Handling

Learning Objectives

By the end of this lesson, you will be able to:

  • Use exception-throwing libraries
  • Use exception handling effectively
  • Acquire and release resources in a way that respects exceptions without creating leaks
  • Implement best practices to incorporate exceptions in Java

Introduction

Exception handling is a powerful mechanism for handling erroneous cases that occur while our code is running. It enables us to focus on the main execution of the program and separate the error-handling code from the expected execution path. The Java language forces programmers to write exception-handling code for library methods, and IDEs such as IntelliJ, Eclipse, and so on help us generate the boilerplate code necessary. ...

Get Java Fundamentals 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.