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
Is alive method in java?
What is a website container?
Explain jdk, jre and jvm?
Why does my function print none?
In how many ways we can do synchronization in java?
What does regex mean?
What is a nullable field?
What is balanced tree in java?
What are the important features of Java 11 release?
what is static import in java? Explain
What is stringjoiner ?
What is a method in coding?
When a thread is executing synchronized methods , then is it possible to execute other synchronized methods simultaneously by other threads?
What will happen when using pass by reference in java?
Do we have pointers in java?