What are exceptions and why to handle exceptions ? Exception are the conditions that occurs unexpectedly, i.e it makes a system to an undefined state. In other words it can be defined as a abnormal condition.
What are exceptions and why to handle exceptions
What are exception in programming language :
Exception is defined as run time error. The code which is not understand at run time, cause an error. For example, while seven divides by zero i.e 7/0 is syntax wise correct, but at run time, it cannot be evaluated, as 7/0 gives infinite or undefined answer. In most of the programming language, exception handling is supported while, some language like C language does not support exception handling. You can see here how, exception can be handle in java with the help of try catch block or throws and throw.
So we need to handle exception but why to handle Exceptions :
Exception handling is a very crucial part of enterprise applications
1. Robust : Robust System, can be defined as a system which can function any where prior to any condition. Exception are to be handled to make application robust.
2. Correct Evaluation : Exceptions are to be handle properly, as if any exception occurred, it make executor to that part of code where the exception is to be handle. As the
3. Security : Security is consolidated issue. For example SQLException if not handled properly, at run time, the some part of that code might be exploited and used easily by hackers.
4. To make user aware of system inputs : A delay or some unexpected condition can leave the user frustrated. So When exception occur the reason for unexpected condition occurrence is properly defined in handling exception and makes aware the user that, which type of input they should avoid to use.
5. Avoids Failure of system or system crashes.
6. It makes application remain fault tolerance
Its time to handle exception. Here are couple of articles which you may be interested to read for handling exception in java.