Here we will discuss What Is Exception Handling And How Many Types Of Exceptions Are There In Java? The exception is a situation in OOPs programming where further execution of the program is not possible due to some error, Or we can say when some error occurs in execution. To handle such conditions we introduced a concept called exception handling.
What Is Exception Handling?
It is a way to handle the situation of some run time error that could occur while executing of program, For example, we divide two numbers in a program, and due to input entered the divider become then how can a zero divide a number then it could give an ArithmeticException which could handle it using a catch block.
Similarly, we can have a number of types of exceptions depending upon the error that occurred so let’s discuss the types of exceptions.
Types Of Exceptions
There are around ten types of exceptions but here we will discuss six most important types of exceptions
IO Exceptions
This exception occurs when we try to read a file that does have things, which means we are trying to read the line which even does not exist in such case IOException occurs.
ClassNotFound Exceptions
This exception occurs when JVL could find the class requested, The reasons for not being able to find the class could be the path is not entered correctly, a Command line error, or even if there is no such class exists.
NullPointer Exception
This type of exception occurs when we try to access the object with the help of a reference variable whose value is null. in that case, the variable would be pointing to a null value so the exception occurred.
ArrayOutOfBound Exception
It is an exception which occurs when we try to access the index of an array where the entered index number does not exist means the size of the array is not sufficient to get the element of that index.
NuberFormate Exception
This exception occurs when we pass a string in reference and we can not convert it into a number so that we can perform our task, At times we have to convert a string into a number which could not be possible.
Arithmetic Exception
They are the exceptions where we try to perform a task that is impossible in arithmetic operations for example dividing a number by Zero which is practically not possible so the arithmetic exception will occur in such case.
Blocks Of Exceptional Handling
there the 3 three clocks of exceptions.
Try Block
It is a block where we write the expression where the exception could occur so that we know where the exception could occur.
Catch Block
It is a block that deals with the handling of the exception. Mean once the exception occurs the catch block need to be executed to know that exception occurs.
catch block does not execute if the exception does not occur. And there can be more than one catch block present in an exception to be executed.
Finally() Block
As we have a catch block to execute if an exception occurs in the try block but Finally is a block that needs to be executed at any condition weather the exception occurs or not.
Learn more about What Is Exception Handling And How Many Types Of Exceptions Are There In Java?: Exceptional Handling
And also visit JAVA TUTORIALTo Learn More about java and solve your problems.