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
Write java program to reverse string without using api?
Explain different forms of polymorphism?
Can list have duplicates in java?
how would you implement a thread pool? : Java thread
Why object class is super class for every class in java?
What is null mean in java?
How many types of voids are there?
Why javac is not recognized?
What is the main purpose of java?
What is purpose of applet programming?
How to make a read-only class in java?
Tell me are there implementations for sorting and searching in the java libarary?
What is a native method in java programming?
What is square root in java?
What is mvc in java?