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 the java virtual machine?

569


What is serial version uid and its importance in java?

588


Why we used vector class?

617


How can you say java is object oriented?

579


What are inbuilt functions in java?

551






Difference between Linked list and Queue?

595


What are synchronized methods and synchronized statements in java programming?

564


What is the final keyword in java?

543


What are the loops in java?

513


What is hashing principle in java?

544


What is the basic difference between string and stringbuffer object?

571


What is the difference between path and classpath variables?

515


Why is a singleton bad?

546


How do you escape a string?

496


What is meant by javabeans?

603