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
List out benefits of object oriented programming language?
What is the difference between the size and capacity of a vector?
Can static method access instance variables ?
What is difference between word and integer?
What is the full meaning of java?
Why convert an applet to an application?
How can we run a java program without making any object?
What is the use of using enum to declare a constant?
What is t in parametric equations?
How will you compute size of a structure?
What is sizeof in java?
What is void in java?
What is the difference between declaration and definition in java?
Explain covariant method overriding in java.
How many bits is a char?