what is difference between throw and throws in exception?
Answer Posted / basant
) throws keyword gives a method flexibility of throwing an Exception rather than handling it. with throws keyword in method
signature a method suggesting its caller to prepare for Exception declared in throws clause, specially in case of checked Exception and provide sufficient handling of them. On the other hand throw keyword transfer control of execution to caller by throwing an instance of Exception. throw keyword can also be used in place of return as shown in below example:
private static boolean shutdown() {
throw new UnsupportedOperationException("Not yet implemented");
}
as in below method shutdown should return boolean but having throw in place compiler understand that this method will always throw exception .
Read more: http://javarevisited.blogspot.com/2012/02/difference-between-throw-and-throws-in.html#ixzz1xaAnuuuu
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is function overriding and overloading in java?
Explain about arraylist?
What are the five major types of reference sources?
What is method reference?
What is sorting algorithm in java?
What is variable and example?
What is off heap memory?
Is it possible to define a method in java class but provide it’s implementation in the code of another language like c?
How does map works in java?
How do you read a char in java?
What are 4 pillers of object orinted programming?
Which java collection does not allow null?
How can we make a class virtual?
What technique is carried out to find out if a particular string is empty?
What is assembly condition codes?