Exceptions:- Exception is a condition Which is Responsible for Occurrence of Error Like Divide by Zero is an condition that never be possible So we can call it an Exception which halts or stops the Execution of Program In java there is an Exception Class Which is Responsible for producing an Error Message when an Error has occurred.
when an Exception has occurred then compiler will never reach to the Code that is placed after the block which contains an error. So that there is special Mechanism given by java for handling Exceptions When as Exception has occurred then the Compiler will generate an Exception Code to an Exception Class and with the help of Exception object. So if we wants to Execute Statements then we have to handle Exception For handling Exceptions java provides us special Mechanism which is called as Exception handling Mechanism Java provide following Methods for handling Exceptions those are occurred in a program
There are Many Exceptions those may be occurred when there is an Error in code of java Every Error May Cause an Exception that is Specific and Compiler will understand it clearly When an Exception has occurred then there is Specific Exception Class that will Generate the Error Message to the user There are Many Exception Classes that Gives the Message to the user .The Various Types of Exception Classes are as Follows:-
1 ) Arithmetic Exception :- This Exception Will Occur when you are performing wrong Arithmetic Operations Like you are dividing a Number by zero When you are Dividing a Number by zero then compile gives us an error Message that will be Generated by Arithmetic Class
2) Array Index out of Bound Exception: - This Exception Will Occur when you are Accessing the Element of an Array that is doesn’t Exists like Accessing 6th Element out of 5 Elements
3) NullPointerAssignment :- Occur when Performing the Operations on Null String
4) InvalidTypeCasting :- When you are Converting a data type into type into the invalid data type