what is difference between throw and throws in exception?

Answer Posted / raj

throws --> throws declare that it throws the exception to
the calling method.

throw --> it is surrounded by the try catch block actually
it does the work, of throwing the exception.

For Example:

public void testMethod() throws BusinessException
{
try
{
}
catch(Exception exe)
{
// catch all the exceptions and provide some meaningful
message
throw BusinessException("An error occured while
trying to connect to DB");
}

}

Is This Answer Correct ?    43 Yes 13 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How many bits are in a sentence?

822


What is the difference between normal report & matrix report?

868


Is java type safe?

766


What is nested loop? What is dangling else condition in it?

837


What is difference between == equals () and compareto () method?

764


What are implicit objects in java?

771


What is length in java?

784


What is factor r?

747


What are the advantages of passing this into a method instead of the current class object itself?

1433


What is this keyword used for?

894


Is zero a positive integer?

794


What is a flag variable?

755


Is a copy constructor?

853


Explain the importance of throwable class and its methods?

803


What is passed by reference and pass by value ?

795