why there are multiple catches for a try block.don't tell me
that there can be multiple exception of a code segment
that's why.tell me the real fact behind this.

Answer Posted / reshma

Multiple catch is necessory when the try when the try block
hase statements that raise different types of exceptions.

The single catch block will not be able to handle the
multiple error condition without complex coding. For
example close the database connection and closing of a file
For a particular exception closing of database connection
can be written in one catch block, for another kind of
exception we can close the file in another catch block.
That means if a file is opened and a database connection is
established, we want to release only one resourse at a time
for a particular exception.

When an exception is thrown it traverses through the catch
block until the matching catch block is found.

I hope my understanding is correct......

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How hashmap works in java?

784


Is java code slower than native code?

749


What is the difference between an inner class and a sub-class?

701


What is a parameter in matrices?

736


Can you create an object of an abstract class?

753


What is the difference between import java.util.date and java .util?

803


What are different types of constants?

713


How can you handle java exceptions?

716


What is sortedmap in java?

760


What is regex used for?

733


How do you convert an int to a string in java?

773


What is the difference between Java and C++?

824


What is the difference between variable declaration and variable initialization?

731


What all access modifiers are allowed for top class ?

937


Which category the java thread do fall in?

749