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 kind of variables a class can consist of?
What is difference between final and finally in java?
Is hashmap thread safe?
What is the static import?
How do you convert int to char in java?
What are the advantages of exception handling in java?
What are 5 boolean operators?
What does compareto () do in java?
What are different data types?
How many digits is int32?
What does a za z0 9 mean?
Are arrays passed by reference in java?
What is use of static in java?
What are the changes in java.io in java 8 ?
What are the characteristics of java?