Types of exceptions

Using of standard Java exceptions simplifies the understanding of every project. But they are much exceptions that we can use and it's not always simple to found the right one.

Data Engineering Design Patterns

Looking for a book that defines and solves most common data engineering problems? I wrote one on that topic! You can read it online on the O'Reilly platform, or get a print copy on Amazon.

I also help solve your data engineering problems 👉 contact@waitingforcode.com 📩

In this article we'll focus on different types of exceptions in Java. To simplify the reading, we won't divide this article on different parts. Instead of it, all exceptions will be presented in two tables : one for unchecked exceptions and another one for checked exceptions. The difference between these two types is that ones are can be detected at conception time and the others only at runtime.

Exceptions detected at conception time are called checked ant they must be caught or thrown. They also can be predicted, for example: when we try to work with a non-existent file with FileInputStream, an FileNotFoundException can be thrown. This type of exceptions is declared at API level.

Unchecked exceptions are more difficult to predict and occur at runtime, for example because of unexpected input as the operations on null object while it was expected to be not null.

Types of checked exceptions

See checked exceptions in Java

Unchecked exceptions

See unchecked exceptions in Java

We saw that several exceptions exist in Java to handle different strange scenarios. We can use IllegalThreadStateException to handle a Thread's bad state or IllegalAccessException on trying to access to a non-visible method or field. You should use these exceptions to facilitate the understanding of your code. Is better to see explicitly that in some method only restricted values of arguments are accepted at development time, rather than discover a bug in runtime environment without knowing its origine.

Consulting

With nearly 16 years of experience, including 8 as data engineer, I offer expert consulting to design and optimize scalable data solutions. As an O’Reilly author, Data+AI Summit speaker, and blogger, I bring cutting-edge insights to modernize infrastructure, build robust pipelines, and drive data-driven decision-making. Let's transform your data challenges into opportunities—reach out to elevate your data engineering game today!

👉 contact@waitingforcode.com
đź”— past projects


If you liked it, you should read:

📚 Newsletter Get new posts, recommended reading and other exclusive information every week. SPAM free - no 3rd party ads, only the information about waitingforcode!