Exception Handling in Java
In this section we will discuss about Exception and Exception handling in java programming language.
What is exception?
Exception means that abnormal condition, An exception is abnormal condition that disturb the normal flow of the program. Whenever exception occurs the program gets terminated now and rest of code will not execute.
In java exception are also represented via objects.
What is exception handling?
The Exception Handling is a way (mechanism) to handle runtime errors such as IllegalAccessException, IO, SQL, Remote etc.
Reasons behind the Exceptions
There can be many reason for occurring exception for example open non existing file or loading non existing class etc.
Benefits of Exception Handling
The main benefit of exception handling is to maintain the normal flow of execution of the java program. Basically exception terminates the program when occurs that is why exception handling play important role in java programming language.
Need of Exception Handling
Exception Handling is basically used to maintain the normal flow of execution of program and print the user friendly message.
Let take an example
Exception in thread "main" java.lang.ArithmeticException: / by zero at ExceptionDemo.main(ExceptionDemo.java:5) ExceptionDemo : The class name main : The method name ExceptionDemo.java : The filename java:5 : Line number
End user cannot understand this type of message. You can easily handle these type of exception and prints user friendly message through exception handling.