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


Please Help Members By Posting Answers For Below Questions

Write java program to reverse string without using api?

558


Explain different forms of polymorphism?

661


Can list have duplicates in java?

523


how would you implement a thread pool? : Java thread

510


Why object class is super class for every class in java?

581






What is null mean in java?

627


How many types of voids are there?

541


Why javac is not recognized?

530


What is the main purpose of java?

522


What is purpose of applet programming?

644


How to make a read-only class in java?

595


Tell me are there implementations for sorting and searching in the java libarary?

603


What is a native method in java programming?

532


What is square root in java?

590


What is mvc in java?

560