Exception Handling in java

The word exception in world in java means run time error and the word exception handling means the way our program behaves whenever the run time error occurs. But we can understand the importance of exception handling we must first understand how the java behaves by default when a exception occurs.



    When a exception occur in java the jvm takes two action by default.

 1)It immediately terminates our program as soon as an exception occur.

      2)It displays a technical error message related to the exception on our output screen.


         Both the above behavior are very much non-user friendly because 
      1) Termination a program will not allow further code to execute even if that code has no relation with exception that has occurs.

   2) If the error message will be technical the user will not be able to understand the problem and might repeat wrong input again.



         To change the both above statement java strongly recommended to apply exception mechanism in their program. 


     So by use of exception handling our program will not be terminated abnormally and we can also make our error message user friendly. 


      Thus exception handling mechanism is an integral part of every java program and should always be used.


Exception Handling keywords


    java provides us five keyword related to exception handling each of them has a unique use and must be use wisely in our program :-

1)try
2)catch
3)throw
4)throws
5)finally
.

Comments