Understanding exceptions
In everyday life, we have to execute a lot of processes. And all the time, we have little hiccups that happen, and these should not ruin our day. These hiccups are not considered the happy path of events, but they happen often, and we recover from them and continue business as usual.
There are also more serious problems that can occur, for which we need to have a formal backup plan, such as evacuating a building in case of a fire.
Exceptions in Java are like this. These are things that should not happen; sometimes, we are in control of them happening and sometimes, we are not. In some cases, we are obligated to specify a backup plan, and in other cases, we are not. First, let’s talk a bit more about what exceptions are.
What are exceptions?
Exceptions are events that disrupt the normal flow of the program. They typically arise from errors or unexpected conditions that the program encounters while running. Exceptions in Java are objects. These...