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 integers and example?
why we use merge option in hybernate pls give a ex snippet
Why parsing is done?
How many ways can we create singleton class?
Which variables are stored in heap?
Is java type safe?
Can a final variable be initialized in constructor?
What does int argc char * argv [] mean?
Can you override private or static method in java?
Why java is called not pure object oriented language?
why not override thread to make a runnable? : Java thread
What initialize variables?
What is the lifetime and scope of a variable?
Can we synchronize static methods in java?
Is singleton set an interval?