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

Can java hashmap have duplicate keys?

735


What technique can be employed to compare two strings?

803


What does sprintf mean?

735


Is java call by value?

833


What are the advantages of java over cpp?

829


Is java 9 released?

749


what is the difference between Object Based Language and Object Oriented Language?

810


What is string in java? String is a data type?

779


What is singleton class in ruby?

807


Can you instantiate the math class in Java?

822


What is anti pattern in java?

743


Give an example of call be reference significance.

820


Explain 5 io best practices?

816


What are serialization and deserialization?

989


Why do we need strings in java?

723