15 Exception Handling

Exceptions in Java are objects. All exceptions are derived from the java.lang.Throwable class. Exceptions can be handled in Java using try-catch-finally construct. Exceptions thrown by the try block of code is caught (handled) by the catch block.

The following code shows an example of the try-catch-finally construct.

The output of the above example

Whenever an exception is thrown by try block of code, it looks for catch construct which handles that exception. If no catch construct is found which handles the exception, then the exception is handled by default exception handler. Catch construct is not executed if no exception is thrown or if the respective catch construct does not handle the specific exception. For example, in the code above, the catch construct only catches ArithmeticException. Any other exception, say FileNotFound will not be handled by this catch construct. Finally, the code block is executed, no matter an exception is thrown or not. An example for use of finally construct can be to write a code that closes DB connections. This will ensure that DB connection is closed, no matter an error happens or not during data retrieval from DB.


Rohini .R said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
Selenium Training in Bangalore | Selenium Training in Bangalore | Selenium Training in Bangalore | Selenium Training in Bangalore

cathryn leno said...

I am really happy with your blog because your article is very unique and powerful for new reader.
Click here:
selenium training in chennai
selenium training in bangalore
selenium training in Pune
selenium training in pune
Selenium Online Training

Richa T said...

Thank you so much for a well written, easy to understand article on this. It can get really confusing when trying to explain it – but you did a great job. Thank you!

Java training in Chennai | Java training in USA |

Java training in Bangalore | Java training in Indira nagar | Java training in Bangalore | Java training in Rajaji nagar

nivatha said...

This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
Data Science training in rajaji nagar | Data Science Training in Bangalore
Data Science with Python training in chennai
Data Science training in electronic city
Data Science training in USA
Data science training in pune

sai said...

Thank you for an additional great post. Exactly where else could anybody get that kind of facts in this kind of a ideal way of writing? I have a presentation next week, and I’m around the appear for this kind of data.

python training Course in chennai
python training in Bangalore
Python training institute in bangalore

saran latha said...

I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 
Devops Training courses
Devops Training in Bangalore
Best Devops Training in pune
Devops interview questions and answers

Anonymous said...

It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...

angularjs Training in chennai

angularjs-Training in tambaram

angularjs-Training in sholinganallur

angularjs-Training in velachery

angularjs Training in bangalore

Dharani M said...

selenium training centers in Marathahalli

best software testing training institutes in Marathahalli with placements

automation testing courses in Marathahalli

selenium testing course in Marathahalli

software testing institutes in Marathahalli

selenium training in Marathahalli

best selenium training in Marathahalli

selenium course in Marathahalli

Unknown said...

Thanks for sharing such a valuable information sap institute in Hyderabad

vimal kumar said...

Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.
Devops Training in bangalore
Digital Marketing Training in bangalore
Data Science Training in bangalore
Java Training in bangalore

jefrin adams said...

Good to read thanks for sharing
DevOps Training Institute in Chennai

Unknown said...

Thank you so much for posting this. I really appreciate your work. Keep it up. Great work!Best software training company with placement in Hyderabad

Jagadeesh said...
This comment has been removed by the author.
prash p said...

Awesome information.
such an useful article.
thanks for posting.keep sharing.

jenifer irene said...

I read the post and I have really enjoyed your blogs posts. Looking for the next post.
Aviation Academy in Chennai
Air hostess training in Chennai
Airport management courses in Chennai
Ground staff training in Chennai
aviation institute in Chennai
Air Hostess Training Institute in Chennai
Airline Courses in Chennai
airport ground staff training in Chennai

sandeep saxena said...

Thanks a lot for a good blog. In this blog, I gain more knowledge about technology.
Struts Training in Chennai
Struts Training Chennai
Wordpress Training in Chennai
wordpress course fees
Best Wordpress Training in Chennai
WordPress course
Spring Training in Chennai
Hibernate Training in Chennai

priya rajesh said...

Excellent blog with unique content, thanks a lot for sharing this. I love to learn more about this topic.
Data Science Training in Chennai
Data Science Certification in Chennai
R Programming Training in Chennai
R analytics Training in Chennai
Machine Learning Training in Chennai
Machine Learning course
Data Science Training in Velachery
Data Science Course in Chennai