A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Exception Handling

What is Exception Handling

What is Exception?

  • An Exception is an abnormal flow of Data that interrupts the normal flow of the program.

  • An exception occurs during the execution of program when something goes wrong.

The exceptions can happens for different reasons like :-

  • When we are looking for files and files are not present on that location from where we are accessing.

  • We are filling the data in the form and we have entered the invalid data.

  • When we are communicating via remote and network connection has been lost and we have lost the communication in middle etc.

In a normal way, when resources are not available, then exceptions occur and because of these exceptions our rest of data will not execute either it is right, also it may cause for a system failure it can also impact on system security vulnerabilities..

Without handling these exceptions our good program may stop running altogether, to handle the exceptions we use Exception Handling.

What is Exception Handling ?

  • It is a process to handle or deal with the exceptions is called Exception Handling. It helps us to maintain the flow of execution and get expected output.

  • Exception handling make sure that exception doesn’t break the flow of the program, it means rest of the program will execute after the occurrence of the Exception.

Types of Exception?

There are two types of Exceptions.

  • Checked Exception

  • UnChecked Exception

Checked Exception

  • It is a subclasses of Exception class.

  • compile time Exceptions comes under the Checked Exception it is typically a user error.

  • The exceptions which needs to catches and handled during compile time.

  • These Exception occurs by userend and have to handle it by ourselves.

  • We can not ignore these Exception at compile time.

  • These exceptions usually happen because of unavailable resources like- database complications, network connection issue, files missing invalid input etc.

  • In checked Exception compiler gives the reminder to programmer to handle failure situation on time.

  • To handle the Checked Exception we use throw keyword in a method.

Types of Checked Exceptions:-

  • IOException

  • SQLException

  • DataAccessException

  • ClassNotFoundException

  • ServletException

  • FileNotFoundException

  • EOFExceptions

UnChecked Exception:-

  • It is a subclasses of Exception class.

  • Runtime Exceptions comes under the UnChecked Exception and Error.

  • These exceptions we can not verified during Compile time.

  • Unchecked Exception is best because it doesn't reduce code readability.

  • Unchecked Exception reflects some error inside the program logic

Types of UnChecked Exceptions:-

  • ArithmeticException

  • IllegalArgumentException

  • NullPointerException

  • ArrayIndexOutOfBoundsException

  • NumberFormatException

  • AssertionError

  • AWTError

  • SecurityException

  • TypeNotPresentException

  • UnsupportedOperationException

  • EnumConstantNotPresentException


  • It is a problems that arise beyond the control of the user or the programmer.

  • The Errors are abnormal conditions that should never be happen.

  • The Errors happens because of the environment in which application is running.

  • It is impossible to recover the Errors.

  • Errors cannot be handle by using try-catch blocks.

  • Errors also happens at Runtime so it is called Runtime Exception or unchecked Exception.

  • It comes under java.lang.Error.

Types of Error:-

  • OutOfMemoryError it occurs when JVM runs out of memory.