ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
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.
 Question Submitted By :: Rasmita Sahoo
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
# 1
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 ?    4 Yes 0 No
Reshma
 
  Re: 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
# 2
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
Raj
 
 
 
  Re: 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
# 3
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 ?    0 Yes 0 No
Tulasi Prasad
 
  Re: 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
# 4
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
Puneet Khanna
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
Can we inherit the constructor in a Class?please give one example. iGate3
what is prepare statement? what is calabedtarement? Symphony1
How to add two numbers with out using Arithmetic , union operators in java....? But we can use bitwise operators... but how...? CTS2
What are the steps to do connection pooling in weblogic? TCS1
What is Hash Code in Java? Cognizent1
What is the difference between a Window and a Frame?  1
Difference between overloading and Overriding. <Giving a confusing example to test the concept.> (also asked in PA Consultancy Group,iflex,Value chain,IBM,CTS,Accenture, Tarang> Symphony6
Can an exception be rethrown? Wipro4
how to handled exceptions & erros in ejb? Satyam1
How the threads are synchronized? BMC2
explain about jre and jvm  2
why String class is immutable. iGate3
What is the difference between add() and addElement() method in Vector Class ? TCS2
Is JRE required to compile Java files ? HCL3
How you can create a radio buttion using Checkbox class?  1
How will you convert an ArrayList to Arrays? KPIT3
What is the immediate superclass of Menu?  1
Explain the concept of polymorphism with examples?  4
To obtain design information about an object, which class in used?  1
what are class,constructor and primitive data types?  2
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com