The process of converting system error messages into user-friendly error messages is known asException handling. This is one of the powerful features of Java to handle run time errors and maintain the normal flow of java applications. 

It is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions.

Why use Exception Handling

Handling the exception is nothing but converting system error-generated messages into a user-friendly error message. Whenever an exception occurs in the java application, JVM will create an object of appropriate exception of sub-class and generates a system error message, these system-generated messages are not understandable by a user so need to convert it into a user-friendly error message. You can convert system error messages into user-friendly error messages by using the exception handling feature of java.

For Example: when you divide any number by zero then the system generates / by zero so this is not understandable by a user so you can convert this message into user-friendly error message like Don't enter zero for the denominator.  

Type of Exception

  • Checked Exception
  • Un-Checked Exception

Checked Exception

Checked Exception are the exception which checked at compile-time. These exception are directly sub-class of java.lang.Exception class.
Only for remember: Checked means checked by compiler so checked exception are checked at compile-time.

Un-Checked Exception

Un-Checked Exception are the exception both identifies or raised at run time. These exception are directly sub-class of java.lang.RuntimeException class.

 Note: In real time application mostly we can handle un-checked exception.
 Only for remember: Un-checked means not checked by compiler so un-checked exception are checked at run-time not compile time.

Handling the Exception

Handling the exception is nothing but converting system error generated messages into user-friendly error messages in other words whenever an exception occurs in the java application, JVM will create an object of appropriate exception of subclass and generates a system error message, these system-generated messages are not understandable by a user so need to convert it into a user-friendly error message. You can convert system error messages into a user-friendly error message by using the exception handling feature of java.

Use Five keywords for Handling the Exception

  • try
  • catch
  • finally
  • throws
  • throw

    Syntax : 
    try
    {
            // statements cause problem at run time
    }
    catch( type of exception - 1 object - 1 )
    {
            //statements provides user friendly error message
    }
    catch( type of exception - 2 object - 2  )
    {        
            //  statements provides user friendly error message
    }
    finally 
    {
                // statements which will execute compulsory
    }

Program:

class ExceptionDemo { public static void main(String[] args) { int a=10, ans=0; try { ans=a/0; } catch (Exception e) { System.out.println("Denominator not be zero"); } } }

Output:

Denominator not be zero

  • Progamming is what actually means ?
  • What is software development ?
  • How we categorized software development in different manner.
C Programming
C Plus Plus
Python
Java Development
Web Designing
Javascript
Mysql
Oracle
We cover all the programming concepts in various programming languages, this tutorials are very help full for bigener as well as Experience developer, for the ease of understanding we categorized programming in different manner likewise.