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 causes memory leak in java?
What is difference between public static and void?
Is java programming easy?
What is a lightweight component?
What restrictions are placed on method overriding in java programming?
Explain the term virtual machine?
Can a private method be declared as static?
Is math class static in java?
What are the files generated after using IDL to java compiler?
How can you read an integer value from the keyword when the application is runtime in java? example?
Explain static nested classes ?
What is method in research paper?
Does java support multiple inheritance or not?
What are the parts of a method?
Is 0 true or false in java?