Sitemap
Surajkh

Surajkh

Passionate Software Developer

Exception Handling in Java

Jun 21, 2023

Exception Handling is a process of handling Runtime Exceptions.

Lets consider the concept of try and catch blocks in order to analyse Exception Handling with the below defined Example.

Press enter or click to view image in full size
Try and Catch Block Example

In the Above Scenario we have basically considered try and catch Block where in if there is any exception occurs then we tend to enter the catch Block.

Get Surajkh’s stories in your inbox

Join Medium for free to get updates from this writer.

Now we can even have a scenario of having Multiple Try and Catch Block as defined in the below Figure.

Press enter or click to view image in full size
Try Block with Multiple Catch Blocks.

Now we might come across a scenario, when we are expected to consider the execution of the statements irrespective of whether an exception occurs or not, that is where finally block comes into picture.

Press enter or click to view image in full size
finally Block

As shown in the above Diagram the finally block gets executed irrespective whether an exception(In this case : (ArithmeticException) occurs or not).

Thank You.

--

--

Surajkh
Surajkh

Written by Surajkh

0 followers

Passionate Software Developer