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 do you do absolute value in java?
How do you get the length of a string in java?
What is an abstract class and what is it’s purpose?
What is the difference between static (class) method and instance method?
What are annotations in java?
What is the difference between an if statement and a switch statement?
What is a jit compiler?
Can you instantiate the math class in Java?
What is a method vs function?
Explain restrictions for using anonymous inner classes?
What data structures are used to perform recursion?
Can array grow dynamically in java?
What is jar?
Difference between start() and run() method of thread class?
Is arraylist sorted in java?