Sitemap
Code Storm

A Medium publication sharing concepts, ideas and codes.

Stop using Exceptions in Java

3 min readMar 29, 2023

--

Facts about exceptions!

Press enter or click to view image in full size
Photo by Joshua Hoehne on Unsplash

Exceptions are a powerful feature in Java that allow developers to handle errors and unexpected behavior in a structured and graceful manner. However, there are cases where exceptions are misused and abused, leading to bloated and hard-to-read code. In this article, we will explore the reasons why you should consider not using exceptions in Java.

Exceptions are expensive

Throwing an exception in Java is an expensive operation. When an exception is thrown, the Java Virtual Machine (JVM) must perform several actions to unwind the call stack, locate the appropriate catch block, and execute it. This process can be slow and can have a significant impact on the performance of your code.

Exceptions are hard to reason about

When you use exceptions to control the flow of your code, it can become difficult to reason about the behavior of your program. Exception handling can be complex and hard to follow, and it can be difficult to predict the behavior of your code when exceptions are thrown.

Exceptions can hide bugs

When you use exceptions to handle unexpected behavior, it can be easy to ignore bugs and other issues in your code. Instead of fixing the root cause of the…

--

--