Why to use exceptions? What is the advantage with exceptions in Java?
i. It provides a way to separate error handling from actual code.
ii. Exception is nice way to propagate error to parent functions or one from to other functions.
iii. Exception provides a nice way to group the errors.
All the mentioned 3 points are advantages of Exceptions in Java.
1. separating error handling from actual code. If you see any c programming code, both error logic and business logic will mixed up, which creates readability and maintainability problem for the programmer.
2. propagating error to upper functions. In languages like C, propagating errors to the previous parent functions chain is very difficult, which was addressed in exceptions.
3. Grouping of errors, is also one of the advantages of Exceptions. In java they have properly grouped various exceptions based on their functionality.
Back To Top