Saturday , April 29 2017
Home / java / What is Exception in Java

What is Exception in Java

Exception:

A statement which is capable of terminating a program abruptly at runtime is known as Exception. In Java they have identified all the possible situations that are capable of terminating a program abruptly and represented them as a hierarchy of classes handled by java.lang.Throwble.

The Throwble is the super class of all the Exceptions and Errors.

Error:

An Error is a class represents the serious situation, which can not be handled programatically. Hence the programmer can not expected to catch or handle the Errors.

Hierarchy of Exception in Java:

Exceptions are broadly classified into two types

  1. Checked Exceptions
  2. Un-Checked Exceptions

 

Exception in Java

Both checked and un checked Exceptions are raised at Runtime. But unchecked exceptions are not explicitly checked during the compilation of the program.

Checked Exceptions :

Checked Exceptions in Java are the Exceptions which are explicitly checked for during the compilation of the program. That is during the compilation time it self the compiler detects the presence of such exceptions and allows the program to compile if and only if the exception has been taken care by the programmer or if and only if the programmer explicitly throws the exception.

UN-Checked Exceptions:

Un checked exceptions are represented by classes which are sub classes of the RuntimeExceptin. The RuntimeExceptions are thrown during the normal operations of the Java Virtual Machine.

Who Creates the Exception Object.?

When a program is submitted to JVM for execution, it starts the execution from the main method and continued till it doesn’t encounter an Exception. If it encounter an exception the JVM immediately identifies¬† the class representing the exception, creates an object of the class and em bides it information capable of helping the programmer to over come the exception. And checks for a mechanism that is capable of overcoming the problem caused and if one is found, it handled over the control along with the object created to that mechanism. In case it doesn’t come across any such mechanism then it handled the exception in its own way by terminating the application.

Exception Handling:

In Java we have the following keywords to handle the Exceptions.

  1. try
  2. catch
  3. finally
  4. throw
  5. throws

You May Also Like : How To Handle Exceptions In Java

About chandrashekhar

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Check Also

Binary Literals Java 7 Example Tutorials

Binary literals is one of the new feature added in Java 7. We already know …

Leave a Reply

Your email address will not be published. Required fields are marked *