Tuesday 27 June 2017

What is Exception handling?

Exception Handling


Questions:-

What is exception handling?

Answer:-

In java,exception is an object or event which is thrown at run-time and it is mechanism to handled run time-error.

what is different between in Error and Exception:-

there are some type of error such as:-

1) Syntax error.

2) Logical error.

3) Run-time error.

Syntax Error-

Syntax error is an error in the syntax a sequence of character.it is cause by a programmer because writing mistake of the programmed. for example:-

1) int a=10;   // it is correct.

2) int 20=b;    // it is not correct so that is a syntax error.

Logical Error-

Logical error is an error, which is extremely find to difficult in the program because they reflect the coding.we can say that logical error is bug which is in the source code such as operator precedence and any number divide by zero.
Let's see Example-

1)   int a=10.5;

2)   for(i=1;i<=10;i++);

Run-Time Error-

Run-time error is also indicate the bugs in the program at the run-time. For Example-

An integer divided by Zero.
int a=20/0;  //  here occurs run-time error.

In run-time error has two part or we can divided in two parts.

1) Handled Error.(It is also called an Exception Error.)

2) UN-handled Error.

Advantages-

Rest of the code is executed or normal flow of the program and an application is maintained.
For Example-

public class ExceptionExample{
public static void main(String[] args){
try{
int a=20/0;
}
catch(Exception e){
System.out.println("rest of the code");
}}

There are two type of Exception:-
1)  Checked.
2)  Unchecked.
Java Exception Hierarchy-