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
If two threads have same priority which thread will be executed first ?
What is a programming object?
What is hashing principle in java?
Difference between abstract and concrete class ?
What do you mean by scope of variable?
Can java hashmap have duplicate keys?
What happens if an exception is throws from an object's constructor?
Can extern variables be initialized?
What's the difference between comparison done by equals method and == operator?
what is the constructor and how many types of constructors are used in java?
How to split a string in java?
What are namespaces in java?
What does it mean to be immutable?
How do you use compareto method?
Can we have any code between try and catch blocks?