© Kishori Sharan 2017

Kishori Sharan, Beginning Java 9 Fundamentals, https://doi.org/10.1007/978-1-4842-2902-6_13

13. Exception Handling

Kishori Sharan

(1)Montgomery, Alabama, USA

In this chapter, you will learn:

  • About error handling in Java using exceptions

  • How to use try-catch blocks to handle exceptions

  • How to use finally blocks to clean up resources

  • The difference between checked and unchecked exceptions

  • How to create a new exception type and use it in your program

  • How to use auto-closeable resources using a try-catch-resources block

  • How to access the stack frames of a thread

  • How to get the class name of the caller of a method

All classes in this chapter are a member of a jdojo.exception module, as declared in Listing 13-1.

Listing 13-1. The Declaration ...

Get Beginning Java 9 Fundamentals: Arrays, Objects, Modules, JShell, and Regular Expressions 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.