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
what are three ways in which a thread can enter the waiting state? Or what are different ways in which a thread can enter the waiting state? : Java thread
Do you need to import math in java?
What is java and why do we need it? Explain
Where is the find and replace?
What is a constructor, constructor overloading in java?
Explain naming conventions for packages?
Is java call by reference?
Explain about oops concepts.
What is a parent class in java?
What is this keyword used for?
What are thread priorities and importance of thread priorities in java?
What will be the initial value of an object reference which is defined as an instance variable?
What is a newline character in java?
What is jar?
How many types of gc are there in java?