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.

4-day workshop · In-person or online

What would it take for you to trust your Databricks pipelines in production?

A 3-day bug hunt on a 3-person team costs up to €7,200 in lost engineering time. This workshop teaches you to prevent that — unit tests, data tests, and integration tests for PySpark and Databricks Lakeflow, including Spark Declarative Pipelines.

Unit, data & integration tests
Medallion architecture & Lakeflow SDP
Max 10 participants · production-ready templates
See the full curriculum → €7,000 flat fee · cohort of up to 10
Bartosz Konieczny
Bartosz
Konieczny

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.

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 đź“©