Motivation behind Exceptions
When we are creating programs, we usually focus on expected scenarios. For example, we will get the data from somewhere, we will extract certain information from the data that we assume to be there, we will send it to somewhere else, and so on. We would like our code to be readable, so that members of our team can clearly understand the business logic and can spot mistakes that we may make. However, in practice, our assumptions may not hold and there can be deviations from expected scenarios. For example, we may not be able to get data because of a problem with the network or the disk. We may receive data that does not fit our assumptions. Or, we may not be able to send data because of similar problems. We have to create programs that behave gracefully in unexpected situations. For example: we should enable the user to retry on a broken network connection. Exceptions are the way we handle such situations in Java without making our code too complex.
As programmers...