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 string syntax?
What are different types of control structures?
What do you mean by append?
What is the default size of set in java?
What are packages in java?
What do bitwise operators do?
What is string in java? String is a data type?
Can we create constructor in abstract class ?
Why string is immutable or final in java
What is function overriding and overloading in java?
What is difference between float and double?
What are examples of modifiers?
What do you mean by byte code?
Is string a wrapper class?
Differentiate between run time error and syntax error.