When try and catch block is used ?

Answer Posted / anandh

Try and Catch block is used for Exception handling..
Try block is used for monitor the errors and using catch
block we can shows to users what type of Exception occurred
in our program ...see the following Example code it can be
useful..


class ExceptionExample
{
public static void main(String args[])
{
int d, a;
try
{
d = 0;
a = 42 / d;
System.out.println("This will not be printed.");
}
catch (ArithmeticException e)
{
System.out.println("Division by zero.");// Here shows
Exception to user
}

}
}

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is gui programming?

521


Why there are some null interface in java? What does it mean?

644


Can we have try block without catch block?

587


What is arguments in java?

523


List some oops concepts in java?

584






What are the states of thread in java?

514


Why is boolean important?

593


Give me example of derived data types.

594


What is the final field modifier?

548


Why a dead thread occurs?

577


How to Sort Strings which are given in List and display in ascending order without using java api.

3772


Can an anonymous class be declared as implementing an interface and extending a class in java programming?

648


what is difference betweem home interface and remote interface?

2117


What is collection sort in java?

556


give an example for encapsulation?

582