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 is the purpose of the main method?
How do you use compareto in java?
How do you escape json?
What is slash r?
Can we declare the static variables and methods in an abstract class?
Explain covariant method overriding in java.
Is it possible to use string in the switch case?
What is the use of singleton class?
What is the console in java?
Explain the importance of throwable class and its methods?
What is keyset in java?
worst case complexities of Quick sort and Merge sort.
Is java code slower than native code?
What is string substring?
What is type parameter in java?