O'Reilly logo
live online training icon Live Online training

Modern Java Exception Handling

Simon Roberts

It’s well known that some of the hardest code to write well is the code that handles things going wrong. In some systems, a special return value indicates a failed function call, Java uses exceptions, and--essentially unique among languages with widespread use--introduced checked exceptions. The checked exception idea is widely criticized, but if used well, it can be very effective in creating more reliable and maintainable code.

More recently, the trend in programming has been towards a more functional programming style, and Java 8 encouraged this with new language features and APIs. Unfortunately, exceptions (whether checked or not) are fundamentally incompatible with pure functional programming, and can be very messy even in a pragmatic “somewhat functional” style.

This session examines the foundations of handling situations that deviate from the “happy path” of our program code, builds a strong understanding of how, when, and whether, to use checked exceptions, and explains how to handle these situations in functional code such as Streams. The session also builds a practical, reusable, approach to solving the problem of integration exception-based code into newer functional code.

What you'll learn-and how you can apply it

  • Distinguish different categories of things that go wrong
  • Apply appropriate handling and recovery techniques to each of the categories
  • Build maintainable checked-exception handling code
  • Handle problems in code with an approach suitable for functional code
  • Integrate exception-based code into functional code such as Streams

This training course is for you because...

  • You want to create more reliable and maintainable code, particularly with respect to handling errors and exceptions
  • You want to write more functional code, for example using the Streams API
  • You want to integrate code that throws exceptions into functional code, for example the Streams API
  • You’re a college student looking for additional learning resources to help you with a Java course you’re taking


You should be comfortable writing code in the Java programming language and able to read code of intermediate complexity. Basic familiarity with generics and lambda expressions will help you get the most from this course, but is not essential.

Materials, downloads, or Supplemental Content needed in advance

  • While not required for participation, it’s a good idea if you have a Java development environment (e.g. NetBeans, Eclipse, Intelli-J IDEA or similar) so that you can experiment with the material you learn in the class.

Recommended Prep:

Java Programming Basics

This course provides an introduction the Java Programming Language and would be particularly appropriate for anyone with minimal background in Java before attending this live training.

Modern Java Collections

This course addresses Java’s collections API in detail and builds basic understanding of the generics mechanism from the usage perspective.

Functional Design for Java 8

This Safari-live course explains how to use Java 8’s syntax and new features but is primarily focused on giving you a practical understanding of the deep power of functional programming. In addition, the advent of Java 8 brought syntax that supports and simplifies coding of many key functional programming concepts into what is surely one of the most-used languages of today.(Live class presented at intervals--search Safari for latest calendar)

About your instructor

  • Simon started out working as a software engineer, specializing in industrial control systems, and had a sideline teaching for a local University in his then-home-town of Cambridge, England.

    In 1995 he joined Sun Microsystems, Inc. as a senior instructor and course developer. Simon spearheaded the introduction of Java training by Sun Microsystems in the U.K. in 1995. He developed the first Java certification exams for Sun before he moved to the U.S. in 1998.

    Since leaving Sun in 2004, Simon has developed and delivered training for clients around the world.

    Simon believes that training should have an immediate purpose and application, and that the most effective training is usually "on the job" mentoring, helping to remove the immediate roadblocks to productivity that so often plague workers in fast moving environments.


The timeframes are only estimates and may vary according to how the class is progressing

Note: This course is delivered using a story-telling style, so topics are not handled in isolation, but interleaved so as to introduce new ideas in the appropriate context, and allow understanding to build incrementally.

  • Differentiating problem types
  • Three and a half ways of handling problems
  • Three ways of controlling execution path in the face of problems
  • Principles for maintainability

Break (10 minutes)

  • Effective checked exceptions
  • When to use unchecked exceptions

Break (10 minutes)

  • Reliable handling of problems without using exceptions

Break (10 minutes)

  • Integrating exception-based legacy code into functional systems
  • Q&A