what is difference between throw and throws in exception?

Answer Posted / balu

throws clause is used when the programmer does not want to handle the exception and throw it out of a method.
throw clause is used when the programmer wants to throw an exception explicitly and wants to handle it using catch block hence throw and throws are contradictory.
throw clause can be used to throw our own exceptions also i.e user-defined exceptions.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you sort in java?

598


What is method overloading and method overriding?

538


What does index mean in java?

542


Why do we need singleton class?

551


What is the file type?

561






Is there a jre for java 11?

558


What does singleton class mean?

539


What is data movement?

665


What is java util?

541


Why java is used everywhere?

592


What are mutable classes?

526


Can you declare a private method as static?

700


Which list is sorted in java?

585


What is output buffer?

570


What is concurrent hashmap and its features?

528