what is difference between throw and throws in exception?

Answer Posted / anu mathew

throws:
Method capable of raising an exception but not handling the
same. i.e to say no Try Catch block is implemented in the
Method, to handle the exception.
The callers should create the Try Catch Block to safeguard
against the exception.
If the above is not followed it would result in Compilation
errors.

throw:
The method that raises the exception also handles the same
in its Catch block.
If unhandled the exception can also be handles by the
Callers Try Catch Block.
Hope this makes sense.

Is This Answer Correct ?    44 Yes 10 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How does compareto work in java?

573


Does hashset allow duplicates in java?

580


What is string [] java?

525


What is the difference between scrollbar and scrollpane?

607


What are different types of expressions?

552






What is internal iteration in java se 8?

625


what are three ways in which a thread can enter the waiting state? : Java thread

571


What is the primary benefit of encapsulation?

554


Is singleton thread safe in java?

546


Explain the significance of listiterator.

587


What is a ?

752


What is the difference between a constructor and a method?

565


Are private methods final?

483


What is the buffer limit?

556


Give differences between Quicksort & Mergesort. When should these sorts be used and what is their running time?

569