what is difference between throw and throws in exception?

Answer Posted / raju

throw : throw is used to throw user defined exceptions.
For ex: MyException written by user.it may be either
checked or unchecked exception.

throws: throws is used to throw exception those are handled by
JVM directly.
throws is used in method declaration to
intimate user that, it throw the exception that must
be handled by calling method.

Note :use throws when your method does not handle exception.

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does 0 mean in boolean?

546


How do you sort in ascending order in java?

524


What is the size of boolean variable?

579


What is function and method in java?

525


What is the concatenation operator in java?

580






What is the exact difference in between Unicast and Multicast object?

1517


What is a singleton in genetics?

568


Why java is a platform independent? Explain

536


What is java thread dump, how can we get java thread dump of a program?

577


Can we clone singleton class in java?

519


How is treeset implemented in java?

496


What is nextline method in java?

568


What is the best definition for data?

523


What is class and its types?

546


What are use cases?

563