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 concurrent hashmap and its features?

755


What is exception in java?

753


Write a function for palindrome and factorial and explain?

855


How do you remove an object from an arraylist in java?

663


I want to persist data of objects for later use. What is the best approach to do so?

806


Explain about field hiding in java?

716


What is a dot notation?

760


Write a function to print Fibonacci series and Tribonacci series?

950


What type of value does sizeof return?

772


What does index mean in java?

739


What is java regex?

741


When can you say a graph to be a tree?

839


What is casting in java programming?

772


Differentiate between array list and vector in java.

867


What is the difference between sop and work instruction?

690