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
What is general methodology?
Name component subclasses that support painting in java programming?
What is the main use of java?
What is a parameter in simple terms?
What is the instance of an object?
What about instanceof operator in java?
Can we return null in java?
How do weakhashmap works?
What is multi level inheritance in java?
What does it mean that strings are immutable?
What is the difference between yielding and sleeping in java programming?
What is empty string literal in java?
How is treeset implemented in java?
How to create an interface?
Can we use string in switch case in java?