Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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.

Answers were Sorted based on User's Feedback



why there are multiple catches for a try block.don't tell me that there can be multiple except..

Answer / 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

why there are multiple catches for a try block.don't tell me that there can be multiple except..

Answer / tulasi prasad

I under stood ur problem, I will expalin with an example

public class Test
{
public static void main(String args[])
{
try
{
int n =2/args.length;
int x[]={1,2};
x[30]=4;
}
catch(ArithmeticException e)
{
System.out.println("Divede by Zero");
}
catch(IndexOutOfBoundsException e)
{
System.out.println("ArrayIndex Out of

Bounds");
}
}
}

if u run with out any commandline argument then u got
divide by zero exception. otherwise u get indexbounds
exception

Is This Answer Correct ?    2 Yes 0 No

why there are multiple catches for a try block.don't tell me that there can be multiple except..

Answer / puneet khanna

You will need to have this for a basic reason that the
exceptions need to be caught and needed to be displayed if
your try block throws an exception say Array out of bound
exception which is a checked exception and you have only one
catch block which has the object of Exception class then
that Exception will be caught but you will not be able to
handle the particular array out of bound exception. so all
you need is to put all the exception in diff catch statement
which your try block may throw followed by the superclasses
of the exceptiontype subclasses .thus this is how you will
be able to handle each exception by its own way.

Is This Answer Correct ?    0 Yes 0 No

why there are multiple catches for a try block.don't tell me that there can be multiple except..

Answer / raj

Handle e\any es\exception at the layer that can handle it
in an efficient manner, else propagate it upwards!

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More Core Java Interview Questions

Explain the difference between jvm and jre?

0 Answers  


What is a stack class in java ?

0 Answers   Akamai Technologies,


What is the use of java?

0 Answers  


difference between arraylist and linkedlist otherthan performance

2 Answers   L&T,


What are bind parameters?

0 Answers  


What are the uses of synchronized keyword?

0 Answers  


Is it possible to override private or static method in java?

0 Answers  


Is it possible to specify multiple jndi names when deploying an ejb?

0 Answers  


What are the 4 types of research methods?

0 Answers  


what is interface in java? Explain

0 Answers  


Write a java program to find the route that connects between Red and Green Cells. General Rules for traversal 1. You can traverse from one cell to another vertically, horizontally or diagonally. 2. You cannot traverse through Black cells. 3. There should be only one Red and Green cell and at least one of each should be present. Otherwise the array is invalid. 4. You cannot revisit a cell that you have already traversed. 5. The maze need not be in the same as given in the above example

0 Answers  


How do you decide when to use arraylist and linkedlist?

0 Answers  


Categories