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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is void a data type?

534


What is an array in java?

636


How do I stop concurrentmodificationexception?

504


What is data type modifier?

525


What is the same as procedures?

527






What is the purpose of object oriented programming?

532


What is the difference between error and an exception?

567


Difference between serialization and deserialization in java?

650


Can I import same package/class twice?

488


What will happen if there is a default method conflict as mentioned above and we have specified the same signature method in the base class instead of overriding in the existing class ?

514


What is a super method?

528


Are generics important java?

519


What are the advantages of defining packages in java?

504


Is ++ operator thread-safe in java?

626


Why string is a class?

542