what is difference between throw and throws in exception?

Answer Posted / raju

throw : throw is used to throw exception by user whenever he
feels to throw exceptions. throw is used to throw
either user defined or runtime exception.
for ex : throw new MyException(), here MyException
is user written exception.
throw new NullPointerException(), here
NullPointerException is RuntimeException.

throws: throws is used by the method to throw exception to
the calling method. And method itself does not able
to handle it so it throws to calling method.

Is This Answer Correct ?    10 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What kind of variables a class can consist of?

640


What is difference between final and finally in java?

589


Is hashmap thread safe?

563


What is the static import?

593


How do you convert int to char in java?

577






What are the advantages of exception handling in java?

650


What are 5 boolean operators?

624


What does compareto () do in java?

574


What are different data types?

577


How many digits is int32?

540


What does a za z0 9 mean?

564


Are arrays passed by reference in java?

492


What is use of static in java?

536


What are the changes in java.io in java 8 ?

558


What are the characteristics of java?

529