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
How many bits are in a sentence?
What is the difference between normal report & matrix report?
Is java type safe?
What is nested loop? What is dangling else condition in it?
What is difference between == equals () and compareto () method?
What are implicit objects in java?
What is length in java?
What is factor r?
What are the advantages of passing this into a method instead of the current class object itself?
What is this keyword used for?
Is zero a positive integer?
What is a flag variable?
Is a copy constructor?
Explain the importance of throwable class and its methods?
What is passed by reference and pass by value ?