What is the difference between throw and throws?

Answer Posted / manish kushwaha

First of all i would say both are reserved keyword in java

In Java Exception handling we are using above keyword throw
and throws.

Difference:
throws: throws clause is always use to propagate method
level exception, when ever you will use this clause, caller
method responsibility is to handle exception trowed by the
same method.

throw: this is the clause use to throw the instance of that
exception, main use of this throw clause is in user define
exception use you have written your own exception when ever
this exception will come you will throw this exception object.

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between char and char *?

552


What is difference between identifier and variable?

462


What is the difference between reader/writer and inputstream/output stream?

545


How will you communicate between two applets?

623


How to make a write-only class in java?

566






What are 5 boolean operators?

612


What is ++ a in java?

561


What is the use of optional ?

556


How do you access command-line arguments within the code?

563


How do you write a scanner class in java?

557


Are arrays primitive data types?

629


What are implicit objects in java?

541


How to Sort Strings which are given in List and display in ascending order without using java api.

3748


What is ternary operator in java?

587


What do you understand by synchronization?

580