Exceptions and Exception Handling in Java

| Last Updated: | In: Java


Hi folks, hope you are doing good, If you are just started with java programming language, then keep your close attention in this post as i will explain very important topic “Exceptions and exception handling in Java”.

There are hierarchy in java to handling the exceptions during your program compilation and run time. We are using the try-catch blocks to catching an exception in program.

What is the exception?

Exception are the events that arises during program execution and disrupt the normal flow of program instructions. It is very powerful mechanism to handle the exception to maintain the flow of your java programs.

Types of Exceptions in Java

There are two types of exceptions in java programming language.

1) Checked Exceptions
2) Un-checked Exceptions

1) Checked Exceptions

There are three checked exception such as SQLException, ClassNotFoundException and DataAccessExeception.

2) Un-checked Exceptions

There are four un-checked exception such as RunTimeException, AirthmaticException, NullPointerExeception and DOMExeception.

Exception Hierarchy

Below diagram will help you to make more understand of java exceptions.

exception handling in java diagram

Behavior of try-catch Blocks

First, statements in the try block are executed. If not thrown any exception by the try block, then compiler passes to the next statement. Second, If an exception thrown within try block, then catch block will executed to catch the exception. Below is simple example of try-catch like:

Below is the complete java class with try-catch block:

Hope this tutorial, helps you to make more understand of exceptions and exception handling in Java. Do like & share this tutorial with your friends and on social media.

Tags: , , , , ,


About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby.


You may also like:

Follow us!

Get Free Access of 380+ Scripts

Don't worry you'll not be spammed!

Featured eBook

WordPress Security Guide

Free Guide: Learn how to implement security guideline in your WordPress site...

DOWNLOAD

Pincode Finder

pincode-finder tool

Online Pincode Finder

Best tool to locate post Office address and pincodes of all india...

SEARCH NOW
Copyright © 2013-2017